PHP Fatal Error: Cannot Unset String Offsets

Save

In the Personal Home Page (PHP) programming language, you change a string -- a sequence of characters -- by using offsets to access and modify individual characters. Employing the wrong PHP functions to manipulate the string characters, however, creates a fatal error that cripples your program. Understand how PHP differentiates between strings and arrays to keep your Web page up and running.

Strings and Arrays

  • The fatal-error message usually appears when you treat a PHP string as if it were a PHP array. An array is an ordered map that assigns values to keys that can be either integers or strings. PHP has specific functions for working with string offsets. Using functions designed for arrays such as "Count" or "Unset" -- a function for destroying a variable -- on strings doesn't work. The PHP.net website states this is not a bug, it's a natural part of the language.

Significance

  • Web-building programs such as Drupal and WordPress use PHP as a core of their systems. However, errors with PHP being unable to unset string offsets can shut down your entire site, an issue noted by WordPress administrators and users in 2010. The issue may also occur when installing a WordPress plugin.

Solutions

  • One way to eliminate the fatal error is to go over the coding for the website, find the incorrect function and change it to one appropriate for strings. However, that option can be very time consuming. Site administrators who don't want to analyze all the code can test various site elements to see if changing them provides at least a temporary fix. In addition, WordPress recommends clearing the values in the ftp_credentials table, found in the wp_options table.

PHP Errors

  • Although PHP includes a default error handler, you can create your own error-handling functions to have PHP approach errors to help you identify the source of issues on your Web page. You create the functions with PHP's "set_error_handler." The functions must employ two parameters, which are specialized variables. These variables are the error code and the error description. In addition, include parameters for the name of the file with the error, such as the line number of the error and the error context. This information is optional, but helps pinpoint the source of the error.

References

Promoted By Zergnet

Comments

Resources

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!