Why won't PHP 5.2.14 display any errors (even from the command line)?

I have found this truly annoying, so here's a strategy for checking the syntax from the command line:

  1. Don't load the ini file.
  2. Turn on display_errors and display_startup_errors explicitly.

php -n -l -d display_errors -d display_startup_errors path/to/your/phpfile.php

$ php -h 
-n               No php.ini file will be used
-l               lint, syntax checking only
-d foo[=bar]     Define INI entry foo with value 'bar'

I'm running a later PHP (5.4.24), but these other answers lack the -d option I found exemplified elsewhere that makes PHP display intelligible parsing errors when running from the command line:

php -d display_errors test.php

This is the best answer to the question I was googling. Running the linter with -l only tells you "Errors parsing foo.php".


You might have to enable display_startup_errors as well:

display_startup_errors  boolean

Even when display_errors is on, errors that occur during PHP's startup sequence are not displayed. It's strongly recommended to keep display_startup_errors off, except for debugging.

You can also try to lint the file with c:\php>php -l test.php to test for syntax errors.