Wednesday, April 01, 2009

PHP error_reporting Code/Cypher

When developing code, a web site, in PHP it's handy to turn on some of the error_reporting functionality during debugging. To determin the correct code(s) to use try this simple Google Docs spreadsheet.

The principle is best explained in the PHP manual (available online and only a Google away), but this may help you understand what's being enabled and disabled and with the code required.

Examples (Lifted from the manual for your understanding):
// Turn off all error reporting
error_reporting(0);

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// Report all PHP errors
error_reporting(E_ALL);

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

?>
PHP is one of the most powerful languages out there for web development, frankly there's not much it can't do when you add the right classes (which is like a DLL or Component on the ASP side) but the advantage is the cost... ZERO. If you want a development environment for your own personal machine, try out VirtualBox or VMWare Server and build one (Ubuntu or Ubuntu Server are great platforms, though OpenBSD, Debian, Fedora and the like are also popular and just as worthy). VMWare's VMTN has ready-to-use VMs you can simply plug in and fire up. I might pre-fab a couple of installations for VirtualBox over the next little while, no promises but if you're stuck let me know and I'll do what I can.

There is no individual ownership when you are part of a team, it's the sum of the parts that makes you the RESILIENT team you need to be.