PHP error reporting

I always forget how to turn on picky error reporting in PHP; specifically, how to make PHP complain when you try to use unitialised variables. This is important if you are teaching PHP, as students typically make many spelling mistakes and/or character case mistakes.

As far as I can tell, to turn on strict error reporting which will catch these sorts of errors, set the following directive in php.ini:

error_reporting = E_ALL

You will need to restart PHP to get this to take effect.

Comments

Oh... now i have no

Oh... now i have no confution about PHP error reporting. Great Information for PHP developers.

Try also... E_STRICT

This can help, especially under PHP5, but can cause no end of false positivies especially if you're using a php4 library (e.g. Pear, Smarty etc)

error_reporting(E_ALL | E_STRICT);

David.

Good point

Thanks David, that's worth bearing in mind, particularly if you are writing all your own code from scratch. Best to be as strict on yourself as possible :)

If it's for students...

...then you should teach them to use an included (well, require_once would be better) config file with error_reporting(E_ALL); as the first line. That way, you're training them to force full error reporting for their code regardless of the server's error reporting level :)

Good point

I will include that in my course from now on. In the past, I've just configured the servers to do this.