PHP 5.6.0 released

Predefined Constants

The constants below are always available as part of the PHP core.

Note: You may use these constant names in php.ini but not outside of PHP, like in httpd.conf, where you'd use the bitmask values instead.

Errors and Logging
Value Constant Description Note
1 E_ERROR (integer) Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted.  
2 E_WARNING (integer) Run-time warnings (non-fatal errors). Execution of the script is not halted.  
4 E_PARSE (integer) Compile-time parse errors. Parse errors should only be generated by the parser.  
8 E_NOTICE (integer) Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.  
16 E_CORE_ERROR (integer) Fatal errors that occur during PHP's initial startup. This is like an E_ERROR, except it is generated by the core of PHP. since PHP 4
32 E_CORE_WARNING (integer) Warnings (non-fatal errors) that occur during PHP's initial startup. This is like an E_WARNING, except it is generated by the core of PHP. since PHP 4
64 E_COMPILE_ERROR (integer) Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine. since PHP 4
128 E_COMPILE_WARNING (integer) Compile-time warnings (non-fatal errors). This is like an E_WARNING, except it is generated by the Zend Scripting Engine. since PHP 4
256 E_USER_ERROR (integer) User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error(). since PHP 4
512 E_USER_WARNING (integer) User-generated warning message. This is like an E_WARNING, except it is generated in PHP code by using the PHP function trigger_error(). since PHP 4
1024 E_USER_NOTICE (integer) User-generated notice message. This is like an E_NOTICE, except it is generated in PHP code by using the PHP function trigger_error(). since PHP 4
2048 E_STRICT (integer) Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code. since PHP 5
4096 E_RECOVERABLE_ERROR (integer) Catchable fatal error. It indicates that a probably dangerous error occured, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle (see also set_error_handler()), the application aborts as it was an E_ERROR. since PHP 5.2.0
8192 E_DEPRECATED (integer) Run-time notices. Enable this to receive warnings about code that will not work in future versions. since PHP 5.3.0
16384 E_USER_DEPRECATED (integer) User-generated warning message. This is like an E_DEPRECATED, except it is generated in PHP code by using the PHP function trigger_error(). since PHP 5.3.0
30719 E_ALL (integer) All errors and warnings, as supported, except of level E_STRICT. 30719 in PHP 5.3.x, 6143 in PHP 5.2.x, 2047 previously

The above values (either numerical or symbolic) are used to build up a bitmask that specifies which errors to report. You can use the bitwise operators to combine these values or mask out certain types of errors. Note that only '|', '~', '!', '^' and '&' will be understood within php.ini.

add a note add a note

User Contributed Notes 9 notes

up
15
Andy at Azurite (co uk)
3 years ago
-1 is also semantically meaningless as a bit field, and only works in 2s-complement numeric representations.  On a 1s-complement system -1 would not set E_ERROR.  On a sign-magnitude system -1 would set nothing at all! (see e.g. http://en.wikipedia.org/wiki/Ones%27_complement)

If you want to set all bits, ~0 is the correct way to do it.

But setting undefined bits could result in undefined behaviour and that means *absolutely anything* could happen :-)
up
7
russthom at fivegulf dot com
2 years ago
The following code expands on Vlad's code to show all the flags that are set.  if not set, a blank line shows.

<?php
$errLvl
= error_reporting();
for (
$i = 0; $i < 15$i++ ) {
    print
FriendlyErrorType($errLvl & pow(2, $i)) . "<br>\\n";
}

function
FriendlyErrorType($type)
{
    switch(
$type)
    {
        case
E_ERROR: // 1 //
           
return 'E_ERROR';
        case
E_WARNING: // 2 //
           
return 'E_WARNING';
        case
E_PARSE: // 4 //
           
return 'E_PARSE';
        case
E_NOTICE: // 8 //
           
return 'E_NOTICE';
        case
E_CORE_ERROR: // 16 //
           
return 'E_CORE_ERROR';
        case
E_CORE_WARNING: // 32 //
           
return 'E_CORE_WARNING';
        case
E_CORE_ERROR: // 64 //
           
return 'E_COMPILE_ERROR';
        case
E_CORE_WARNING: // 128 //
           
return 'E_COMPILE_WARNING';
        case
E_USER_ERROR: // 256 //
           
return 'E_USER_ERROR';
        case
E_USER_WARNING: // 512 //
           
return 'E_USER_WARNING';
        case
E_USER_NOTICE: // 1024 //
           
return 'E_USER_NOTICE';
        case
E_STRICT: // 2048 //
           
return 'E_STRICT';
        case
E_RECOVERABLE_ERROR: // 4096 //
           
return 'E_RECOVERABLE_ERROR';
        case
E_DEPRECATED: // 8192 //
           
return 'E_DEPRECATED';
        case
E_USER_DEPRECATED: // 16384 //
           
return 'E_USER_DEPRECATED';
    }
    return
"";
}
?>
up
3
Anonymous
1 year ago
this would give you all the reported exception list of your configuration.

<?php
function FriendlyErrorType($type)
{
   
$return ="";
    if(
$type & E_ERROR) // 1 //
       
$return.='& E_ERROR ';
    if(
$type & E_WARNING) // 2 //
       
$return.='& E_WARNING ';
    if(
$type & E_PARSE) // 4 //
       
$return.='& E_PARSE ';
    if(
$type & E_NOTICE) // 8 //
       
$return.='& E_NOTICE ';
    if(
$type & E_CORE_ERROR) // 16 //
       
$return.='& E_CORE_ERROR ';
    if(
$type & E_CORE_WARNING) // 32 //
       
$return.='& E_CORE_WARNING ';
    if(
$type & E_COMPILE_ERROR) // 64 //
       
$return.='& E_COMPILE_ERROR ';
    if(
$type & E_COMPILE_WARNING) // 128 //
       
$return.='& E_COMPILE_WARNING ';
    if(
$type & E_USER_ERROR) // 256 //
       
$return.='& E_USER_ERROR ';
    if(
$type & E_USER_WARNING) // 512 //
       
$return.='& E_USER_WARNING ';
    if(
$type & E_USER_NOTICE) // 1024 //
       
$return.='& E_USER_NOTICE ';
    if(
$type & E_STRICT) // 2048 //
       
$return.='& E_STRICT ';
    if(
$type & E_RECOVERABLE_ERROR) // 4096 //
       
$return.='& E_RECOVERABLE_ERROR ';
    if(
$type & E_DEPRECATED) // 8192 //
       
$return.='& E_DEPRECATED ';
    if(
$type & E_USER_DEPRECATED) // 16384 //
       
$return.='& E_USER_DEPRECATED ';
    return
substr($return,2);
}
echo
"error_reporting = " . FriendlyErrorType(ini_get('error_reporting')) .";<br>";
?>
up
0
frozenfire at php dot net
3 years ago
Please note that a bug exists in Xdebug versions up to at least 2.1.2 where E_USER_DEPRECATED is not supported even in PHP 5.3.0+.
up
-1
chris-php at IGNORETHISPART dot cybermato dot com
7 hours ago
How about this?  Unlike the examples below, it will show all the bits that are set, AND handle any bits defined in the future (at least not silently hide them)...

    $strErrorType = "";
    $bit = 1;
    $tmpErrNo = $errNo;
    while ($tmpErrNo) {
        if ($tmpErrNo & $bit) {
            if ($strErrorType != "")
                $strErrorType .= " | ";
            switch ($bit) {
            case E_USER_WARNING:
                $strErrorType .= "E_USER_WARNING"; break;
            case E_USER_NOTICE:
                $strErrorType .= "E_USER_NOTICE"; break;
            case E_WARNING:
                $strErrorType .= "E_WARNING"; break;
            case E_CORE_WARNING:
                $strErrorType .= "E_CORE_WARNING"; break;
            case E_COMPILE_WARNING:
                $strErrorType .= "E_COMPILE_WARNING"; break;
            case E_NOTICE:
                $strErrorType .= "E_NOTICE"; break;
            case E_ERROR:
                $strErrorType .= "E_ERROR"; break;
            case E_PARSE:
                $strErrorType .= "E_PARSE"; break;
            case E_CORE_ERROR:
                $strErrorType .= "E_CORE_ERROR"; break;
            case E_COMPILE_ERROR:
                $strErrorType .= "E_COMPILE_ERROR"; break;
            case E_USER_ERROR:
                $strErrorType .= "E_USER_ERROR"; break;  
            default:
                $strErrorType .= "(unknown error bit $bit)"; break;
            }
        }
        $tmpErrNo &= ~$bit;
        $bit <<= 1;
    }
up
0
PhpMyCoder
4 years ago
Well, technically -1 will show all errors which includes any new ones included by PHP. My guess is that E_ALL will always include new error constants so I usually prefer:

<?php
error_reporting
(E_ALL | E_STRICT);
?>

Reason being: With a quick glance anyone can tell you what errors are reported. -1 might be a bit more cryptic to newer programmers.
up
-2
tedmasterweb at gmail dot com
3 months ago
Setting error_reporting in .htaccess or even httpd.conf can be confusing since you can't combine values as you can in php.ini.

To set error_reporting to return multiple values, just repeat the setting in .htaccess for each type of error you want to see. For example, the default PHP setting (E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED) would be something like:

php_value error_reporting 1
php_value error_reporting 2
php_value error_reporting 4
php_value error_reporting 16
php_value error_reporting 32
php_value error_reporting 64
php_value error_reporting 128
php_value error_reporting 256
php_value error_reporting 1024
php_value error_reporting 2048
php_value error_reporting 4096
php_value error_reporting 16384

Note that this is not exactly the same as E_ALL (if I understand correctly) catches all errors not indicated here, but please correct me if I'm wrong.
up
-2
vladvarna at gmail dot com
2 years ago
function FriendlyErrorType($type)
    {
        switch($type)
            {
            case E_ERROR: // 1 //
                return 'E_ERROR';
            case E_WARNING: // 2 //
                return 'E_WARNING';
            case E_PARSE: // 4 //
                return 'E_PARSE';
            case E_NOTICE: // 8 //
                return 'E_NOTICE';
            case E_CORE_ERROR: // 16 //
                return 'E_CORE_ERROR';
            case E_CORE_WARNING: // 32 //
                return 'E_CORE_WARNING';
            case E_CORE_ERROR: // 64 //
                return 'E_COMPILE_ERROR';
            case E_CORE_WARNING: // 128 //
                return 'E_COMPILE_WARNING';
            case E_USER_ERROR: // 256 //
                return 'E_USER_ERROR';
            case E_USER_WARNING: // 512 //
                return 'E_USER_WARNING';
            case E_USER_NOTICE: // 1024 //
                return 'E_USER_NOTICE';
            case E_STRICT: // 2048 //
                return 'E_STRICT';
            case E_RECOVERABLE_ERROR: // 4096 //
                return 'E_RECOVERABLE_ERROR';
            case E_DEPRECATED: // 8192 //
                return 'E_DEPRECATED';
            case E_USER_DEPRECATED: // 16384 //
                return 'E_USER_DEPRECATED';
            }
        return $type;
    }
up
-4
wolfrageweb.com
4 years ago
-1 sets the error reporting to show all to include strict. Should only be used for development servers.
To Top