Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display (echo/print) the currently set error reporting level in PHP?

I am working on a rather large project (multiple teams) so I don't have complete control over the code. Unfortunately, error_reporting is changed in many places throughout the code. When I get to a certain point in the code, I want to see what error reporting is currently set to. Is there anyway to accomplish this?

like image 610
Trevor Avatar asked Feb 06 '12 21:02

Trevor


People also ask

How do I get PHP errors to display?

Quickly Show All PHP Errors The quickest way to display all php errors and warnings is to add these lines to your PHP code file: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);

Which of the following PHP directive is used to display all the errors except notices?

error_reporting: It displays all level errors except E-NOTICE, E-STRICT, and E_DEPRECATED level errors. display_errors: By default, the value of display_errors is off.

How many levels of error reporting are there in PHP?

How many error levels are available in PHP? There are a whopping 16 error levels in PHP 5. These errors represent the category and sometimes severity of an error in PHP.


1 Answers

http://www.php.net/error_reporting

int error_reporting ([ int $level ] )

Returns the old error_reporting level or the current level if no level parameter is given.

You could also use examples provided by the link in order to cast the level (which is returned as integer) into the string. For example:

function error_level_tostring($intval, $separator = ',') {     $errorlevels = array(         E_ALL => 'E_ALL',         E_USER_DEPRECATED => 'E_USER_DEPRECATED',         E_DEPRECATED => 'E_DEPRECATED',         E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',         E_STRICT => 'E_STRICT',         E_USER_NOTICE => 'E_USER_NOTICE',         E_USER_WARNING => 'E_USER_WARNING',         E_USER_ERROR => 'E_USER_ERROR',         E_COMPILE_WARNING => 'E_COMPILE_WARNING',         E_COMPILE_ERROR => 'E_COMPILE_ERROR',         E_CORE_WARNING => 'E_CORE_WARNING',         E_CORE_ERROR => 'E_CORE_ERROR',         E_NOTICE => 'E_NOTICE',         E_PARSE => 'E_PARSE',         E_WARNING => 'E_WARNING',         E_ERROR => 'E_ERROR');     $result = '';     foreach($errorlevels as $number => $name)     {         if (($intval & $number) == $number) {             $result .= ($result != '' ? $separator : '').$name; }     }     return $result; } 

use it as echo error_level_tostring(error_reporting(), ',');

like image 172
Cheery Avatar answered Oct 12 '22 01:10

Cheery