Php – best practice for log level in PHP

PHPprogramming practices

When programming in C, I often get the advice to turn on many or all warnings and not ignore warnings.

Does the same hold in PHP, should I enable all warnings in the PHP log?

Best Answer

Default log level for PHP excludes notices, ie. it's E_ALL & ~E_NOTICE for PHP 5.2, E_ALL & ~E_NOTICE & ~E_STRICT for 5.3 and E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED for 5.4.

If you're working only with your code, then you're much better off setting it to E_ALL. Seeing notices will save you lot of debugging time, seeing deprecation and compatibility notices, will save you a lot of pain upgrading to newer PHP.

However, if you're working with third party code, turning on all notices (E_NOTICE, E_STRICT and E_DEPRECATED) can lead to spamming of your log, as a lot of older code will generate a notice every few lines of code.

Related Topic