View Full Version : PHP syntax error

07-18-2004, 09:33 AM
I may be missing something obvious here, but when PHP encounters a syntax error, does it give you any idea where the problem is?

If I forget to close a quote or leave out a semicolon, PHP returns a blank screen. From the command line it just returns a 255 error code. Is there some way to get at least a hint of where the problem is? Or am I stuck sifting through it line by line for an hour?


07-18-2004, 11:22 AM
I think that by default on WestHost accounts, PHP is configured so that it does not reveal errors in code to anyone that is viewing a web page. You can either reconfigure that so it does show all errors, or you can enable PHP error logging - I would recommend logging. I can't remember if PHP error logging is turned on by default on each VPS, but here is how to do it if you can't see a PHP error log in /var/log/

1. Edit the /etc/php.ini file.

2. Look for the following (and change them to the values shown):

log_errors = On
error_log = /var/log/php-error-log

Now all you need to do is have a look at the error log to see where the problem lies.

07-18-2004, 02:01 PM
Thanks Fayez! That's exactly what I was looking for.

07-18-2004, 02:14 PM
No problem, Edson.

07-18-2004, 02:21 PM
... and restart Apache of course... :)

You can also turn on logging within the script itself, with something like:

ini_set("display_errors", 1);

and enable error logging with:

ini_set("error_log", "/tmp/error_log");
ini_set("log_errors", 1);

Neither of the above need a restart of Apache.
And can be used to turn on error display/logging for a small section of the script and turn it off again.

07-18-2004, 02:28 PM
Thanks Tim - I had forgotten about the restart.

07-20-2004, 08:46 AM
Of course, PHPs error messages are not alway easy to use. You might get an error on "line 20" that is really caused by a typo on line 10 (e.g. if you forgot to use a closing bracket on an if statement). But it at least is better than a blank page.

I wish someone would come up with a little bugtesting environment for PHP that let you step through a script line by line, track variables, etc.


07-20-2004, 09:07 AM
I think there are some.. try www.zend.com for starters. And Komodo is another I think.
Google for "PHP debugger"...