Picking Up Parsing etc. Errors in PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm using Kate in Linux (and UltraEdit when I have to drop back into
Windows) for writing my PHP code. As a independent, self-employed
developer, I cannot afford a commercial IDE for PHP such as is provided
by Zend.

I'm running PHP (with Apache) on my own machine for my development work.

Is there some way ("strict" settings in the php.ini file, or whatever)
by which I can cut down the time I'm wasting searching for, and
recovering from, silly syntax errors in the code I write?

I've just spend a day, for example, finding a complex two-condition 'if'
statement where I'd simply forgotten to supply the outermost pair of
brackets. The only symptom I was getting was a total absence of HTML
output to the page, and my only debugging "tool" was the provision of
'echo' statements at various places down the PHP code, coupled with the
total commenting out of all PHP code beyond the one currently being tried.

If anybody knows of a free- or shareware PHP syntax checking tool for
Linux, I'd be grateful if they could let me know.

Re: Picking Up Parsing etc. Errors in PHP

Alan M Dunsmuir wrote:
Quoted text here. Click to load it

Yeah, there is a free tool and it's called PHP. ;-)

Seriously, check your error log. Depending on how PHP is configured it
logs all errors to the Apache error logfile or its own error logfile.
You can even filter which kind of errors are reported and if they are
only written to the logfile or also output to the screen. Well, to
stdout actually which will go to your browser. Displaying errors should
not be done on a live machine but only on a development machine for
security reasons!

Check your php.ini for the following:

error_reporting  =  E_ALL
display_errors = On
log_errors = On

A small hint: The PHP and Apache logfiles are quite well documented. You
should read them and not just install some WAMP or LAMP package without
having an idea how everything works together. That's a typical n00b
mistake and not something anyone would do who calls himself a developer.


Re: Picking Up Parsing etc. Errors in PHP

*** Anonymous escribió/wrote (Fri, 08 Feb 2008 19:38:54 +0100):
Quoted text here. Click to load it

Or even better (for PHP 5):

    error_reporting = E_ALL | E_STRICT

-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor austrohúngaro: http://www.demogracia.com

Re: Picking Up Parsing etc. Errors in PHP

Anonymous wrote:

Quoted text here. Click to load it

That was supposed to be configfile, not logfile. :-)

Look at php.ini and all the files in Apache2/conf (especially
httpd.conf) and Apache2/conf/extra.


Re: Picking Up Parsing etc. Errors in PHP

On Fri, 08 Feb 2008 18:58:27 +0100, Alan M Dunsmuir  

Quoted text here. Click to load it

Aside from the allready mentioned method to just run PHP and check the  
errors, here's one that I use with my favourite editor: php -l  
/path/to/file/name.php will ONLY do a syntax check, and report the result.  
No more having to go through the webserver, run the entire code, perhaps  
endlessly type urls/refresh windows. Just a simple key combination in the  
editor here does it.
Rik Wasmus

Re: Picking Up Parsing etc. Errors in PHP

Quoted text here. Click to load it

That's a good suggestion.  It should also catch instances where you use
a variable before it's initialized.

To debug online, I have an initialization script that is included
at the top of every single script I have.  Among other things, the
initialization has the following lines:

if (SHOW_WARN) { // This is set in my config.php script
   $errlog = "/home/my_account/some_path/error.log";     // error log file
   if (file_exists($errlog)) unlink($errlog); // remove prev. error log
   ini_set('display_errors', false);          // prevent pre-header abort
   ini_set('log_errors', true);               // enable error logging
   ini_set('error_log', $errlog);             // set error log file
   error_reporting(E_ALL);                    // report all errors

...and then at the bottom of my master page template I simply
display the error log if it exists, within <pre>...</pre> tags.

This method is necessary when one can't use php -l.  One can't use
php -l when the execution of your script depends on cookies, login
data and other session-related data, responses from FORM submissions,



Re: Picking Up Parsing etc. Errors in PHP


on 02/08/2008 03:58 PM Alan M Dunsmuir said the following:
Quoted text here. Click to load it

Kate also exists for Windows in the KDE for Windows package:

http://windows.kde.org /

Quoted text here. Click to load it

PDT is free. I usually use Kate for editing, but for debugging PDT works
better for me. I always had an hard time setting up debuggers to test
PHP scripts.


Quoted text here. Click to load it

Yes, and the good news is that you already have that tool. Just do:

php -l your_script.php

where php is the PHP CLI executable. This does just syntax checking but
does not run the script.


Manuel Lemos

PHP professionals looking for PHP jobs
http://www.phpclasses.org/professionals /

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org /

Site Timeline