Oregon State University
You are not logged in [Login]

Troubleshooting PHP5 Problems

PHP5 troubleshooting:

  • Is this custom code,
    or if not, what is the name of the application?
  • URL of the page(s) displaying the error message (any and all)
  • Filename and line number:
    Most PHP errors will include a filename and a line number; this is very helpful since the file with the error is not necessarily the same as the URL

Common errors and how to solve them

The following error messages are caused by conflicts with new functions and keywords in PHP5 (since these didn't exist in PHP4, it was perfectly legal to use them in code).


Parse error: syntax error, unexpected T_ABSTRACT, expecting T_STRING
Parse error: syntax error, unexpected T_CATCH, expecting T_STRING
Parse error: syntax error, unexpected T_CLONE, expecting T_STRING
Parse error: syntax error, unexpected T_FINAL, expecting T_STRING
Parse error: syntax error, unexpected T_IMPLEMENTS, expecting T_STRING
Parse error: syntax error, unexpected T_INTERFACE, expecting T_STRING
Parse error: syntax error, unexpected T_PRIVATE, expecting T_STRING
Parse error: syntax error, unexpected T_PROTECTED, expecting T_STRING
Parse error: syntax error, unexpected T_PUBLIC, expecting T_STRING
Parse error: syntax error, unexpected T_THROW, expecting T_STRING
Parse error: syntax error, unexpected T_TRY, expecting T_STRING
These messages will all be followed by a filename and line number.
  • Quick Fix: none
  • Check for: an updated version of the application, if it's not one they wrote themselves.
  • Permanent Fix: rename the function/variable/constant to something that won't conflict with PHP built-in functions. Suggestions: add username or application's name to the beginning of the function or variable (this must be done to every occurrence of the function or constant, not just the place where the error message occurs).

The following are caused by some PHP5 functions handling parameters differently than the PHP4 versions:


Warning: array_merge() [function.array-merge]: Argument #1 is not an array
  • Quick fix: Put casts in the array_merge call. Example:
     $var = array_merge('testo', array(1,2,3,4)); 
    becomes
     $var = array_merge((array)$testo, array(1,2,3,4)); 
  • Check for: an updated version of the application, if available.
  • Permanent Fix: Track down all the code referring to array_merge and initialize variables to arrays before passing them in to array_merge. Example:

        $data = array(1,2,3,4);
        $result = mysql_query('SOME QUERY THAT RETURNS NO RESULTS');
        $testo = mysql_fetch_row($result);
        $newdata = array_merge($data, $testo);
        
    The code above will throw an error in PHP5, because $testo is not an array. The proper fix for this is to ensure that $testo is always an array, like so:

        $data = array(1,2,3,4);
        $result = mysql_query('SOME QUERY THAT RETURNS NO RESULTS');
        $testo = mysql_fetch_row($result);
        if(!is_array($testo)) { $testo = array($testo); }
        $newdata = array_merge($data, $testo);
        

The XSLT module is no longer available in PHP5; code that requires it may display errors like this:

Fatal error: Call to undefined function xslt_create()
  • Quick Fix: none
  • Check for: an updated version of the application, if available.
  • Permanent Fix: rewrite the code to use the XSL module instead.

For more possibilities, see http://php.osuosl.org/manual/en/migration5.incompatible.php.


Central Web Services, Oregon State University, Corvallis, OR 97331 · 541-737-1189
Contact us with your comments, questions and feedback
Copyright © 2006 Oregon State University | Disclaimer