Wednesday, 11 June 2008

A quick PHP testing tip for my first post. PHP's configuration file typically called php.ini is almost as important as the source code of a project in my experience. PHP code can give different results depending on how the environment is set up which can be frustrating when you begin deploying to a different environment and things start going wrong. In my case, after developing the first pass of the Esendex PHP ReST SDK I gave it to a colleague to review and it threw warnings. The offender was the following...

if(!defined(ESENDEX_HOME))
{
define('ESENDEX_HOME', '');
}

You might have seen the problem straight away, the defined function requires a string and not a constant name. The error_reporting property in my php.ini file was set quite low (not including E_NOTICE) so it didn't throw a warning. The quick way of catching all these syntax errors during development is to set the error_reporting property to E_ALL which will throw warnings over any mistake, this can be done with the error_reporting function.

error_reporting(E_ALL);

Now you get to spend the next half hour going through your project fixing all the bugs you never knew you had!

No comments: