In article <op.t571m4gx5bnjuv@metallium.lan>,
Rik Wasmus <luiheidsgoeroe@hotmail.comwrote:
><alan@moonrake.demon.co.ukwrote:
>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?
>
>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.
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>...</pretags.
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,
etc.
-A
-A