I am Hack Sparrow
Captain of the Internets.

Turning on PHP Error Reporting – PHP error_reporting()

How do you turn on error reporting in PHP?

PHP error_reporting has a changeable value of 'PHP_INI_ALL', which means you can set the value anywhere in the system.

To turn on PHP Error Reporting in your PHP file add this at the top of the file:

ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);

The same can be achieved using the .htaccess file. To turn on PHP Error Reporting using .htaccess file add this in your .htaccess file:

php_flag display_errors on
php_value error_reporting 8191

The integer value of 8191 is the same as 'E_ALL|E_STRICT'. Although integer values and error constants both work for setting the error reporting level, it is highly recommended to use PHP predefined error constants, because integer values may change in future versions of PHP but constants will always point to the intended integer value.

Tip: to get the correspondig integer value of error reporting flag, just echo the PHP error predefined constant parameters their combinations.

echo error_reporting(E_ALL | E_STRICT); // 8191
echo error_reporting(E_NOTICE); // 8
echo error_reporting(E_PARSE); // 2
echo error_reporting(E_WARNING); // 2
echo error_reporting(E_ERROR); // 1
echo error_reporting(E_ERROR | E_PARSE); // 5

The above tip works because the PHP error reporting constants are mapped to real integers. So it's no surprise you can see integer values when you echo them or their bitwise operations.

References

  1. PHP ini_set
  2. PHP error_reporting
  3. PHP Predefined Error Constants
  4. PHP Constants

2 Responses to “Turning on PHP Error Reporting – PHP error_reporting()”

  1. Krrish says:

    The integer value of Error Reporting constants has been updated in new version of PHP.

  2. James says:

    Heres a really cool tool for setting PHP error_reporting: http://www.bx.com.au/tools/ultimate-php-error-reporting-wizard

Make a Comment