PHP troubleshooting

A golden rule

First check whether everything is spelled correctly, that may save you much unnecessary time.

PHP Parse error: syntax error, unexpected end of file

PHP Parse error:  syntax error, unexpected end of file in /xxx/xxx/xx.php on line xxx

That’s probably because you miss a right curly brace } somewhere in the code. You can comment some code and limit down the range where error occurs.

Fatal error: Call to a member function xxx on null in xxx

Notice: Undefined variable: parser in /xxx/xxx.php on line xx
PHP Fatal error:  Uncaught Error: Call to a member function parse() on null in /xxx/xxx.php:xx
  1. Check whether the log also says PHP Notice: Undefined variable: xxx in xxx. If it is, there are 2 cases:
    • The variable is spelled incorrectly.
    • The variable is not defined.
  2. Check whether the object variable the function belongs to is initiated correctly.

Fatal error: Class ‘xxx’ not found

PHP Fatal error:  Uncaught Error: Class 'modmdMyClass' not found in /xxx/xxx.php:xx
  1. Check whether you spell the class and the include statement correctly.
  2. Make sure include the relevant file with include or require.
  3. Make sure include the relevant file in a correct order. Take a example, a.php uses something of b.php, b.php uses something of c.php and b.php does not include c.php. In a.php, include c.php first then include b.php .