PHP: Hypertext Preprocessor (original) (raw)

Predefined Constants

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

The following constants (either the corresponding numerical value or their symbolic name) are used as a bitmask to specify which errors to report. It is possible to usebitwise operators to combine these values or mask out certain types of errors.

Tip

The name of the constants can be used within php.ini, instead of the raw numerical values to which they correspond to. However, only the|,~,^,!,& operators are understood within php.ini.

Warning

It is not possible to use the symbolic names outside of PHP. For example in httpd.conf the computed bitmask value must be used instead.

[E_ERROR](errorfunc.constants.php#constant.e-error) (int)

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. Value of the constant: 1

[E_WARNING](errorfunc.constants.php#constant.e-warning) (int)

Run-time warnings (non-fatal errors). Execution of the script is not halted. Value of the constant: 2

[E_PARSE](errorfunc.constants.php#constant.e-parse) (int)

Compile-time parse errors. Parse errors should only be generated by the parser. Value of the constant: 4

[E_NOTICE](errorfunc.constants.php#constant.e-notice) (int)

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. Value of the constant: 8

[E_CORE_ERROR](errorfunc.constants.php#constant.e-core-error) (int)

Fatal errors that occur during PHP's initial startup. This is like an [E_ERROR](errorfunc.constants.php#constant.e-error), except it is generated by the core of PHP. Value of the constant: 16

[E_CORE_WARNING](errorfunc.constants.php#constant.e-core-warning) (int)

Warnings (non-fatal errors) that occur during PHP's initial startup. This is like an [E_WARNING](errorfunc.constants.php#constant.e-warning), except it is generated by the core of PHP. Value of the constant: 32

[E_COMPILE_ERROR](errorfunc.constants.php#constant.e-compile-error) (int)

Fatal compile-time errors. This is like an [E_ERROR](errorfunc.constants.php#constant.e-error), except it is generated by the Zend Scripting Engine. Value of the constant: 64

[E_COMPILE_WARNING](errorfunc.constants.php#constant.e-compile-warning) (int)

Compile-time warnings (non-fatal errors). This is like an [E_WARNING](errorfunc.constants.php#constant.e-warning), except it is generated by the Zend Scripting Engine. Value of the constant: 128

[E_DEPRECATED](errorfunc.constants.php#constant.e-deprecated) (int)

Run-time deprecation notices. Enable this to receive warnings about code that will not work in future versions. Value of the constant: 8192

[E_USER_ERROR](errorfunc.constants.php#constant.e-user-error) (int)

User-generated error message. This is like an [E_ERROR](errorfunc.constants.php#constant.e-error), except it is generated in PHP code by using the PHP functiontrigger_error(). Value of the constant: 256

[E_USER_WARNING](errorfunc.constants.php#constant.e-user-warning) (int)

User-generated warning message. This is like an [E_WARNING](errorfunc.constants.php#constant.e-warning), except it is generated in PHP code by using the PHP functiontrigger_error(). Value of the constant: 512

[E_USER_NOTICE](errorfunc.constants.php#constant.e-user-notice) (int)

User-generated notice message. This is like an [E_NOTICE](errorfunc.constants.php#constant.e-notice), except it is generated in PHP code by using the PHP functiontrigger_error(). Value of the constant: 1024

[E_USER_DEPRECATED](errorfunc.constants.php#constant.e-user-deprecated) (int)

User-generated deprecation message. This is like an [E_DEPRECATED](errorfunc.constants.php#constant.e-deprecated), except it is generated in PHP code by using the PHP functiontrigger_error(). Value of the constant: 16384

[E_STRICT](errorfunc.constants.php#constant.e-strict) (int)

Run-time suggestions emitted by PHP about the executed code to ensure forward compatibility. Value of the constant: 2048

Warning

This error level is unused, and has been deprecated as of PHP 8.4.0.

[E_RECOVERABLE_ERROR](errorfunc.constants.php#constant.e-recoverable-error) (int)

Legacy engine "exceptions" which correspond to catchable fatal error. Similar to Error but must be caught via a user defined error handler (see set_error_handler()). If not handled, this behaves like [E_ERROR](errorfunc.constants.php#constant.e-error). Value of the constant: 4096

Note: This error level is effectively unused, the only case where this can happen is when interpreting anobject as a bool fails. This can only happen for internal objects. The most common example, prior to PHP 8.4.0, is using aGMP instance in a conditional.

[E_ALL](errorfunc.constants.php#constant.e-all) (int)

Bit-mask that contains every single error, warning, and notice. Value of the constant: 32767

Found A Problem?

Andy at Azurite (co uk)

14 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 :-)

`

cl at viazenetti dot de

7 years ago

`An other way to get all PHP errors that are set to be reported. This code will even work, when additional error types are added in future.

\n"; } $pot++; } ?>

`

russthom at fivegulf dot com

12 years ago

`[Editor's note: fixed E_COMPILE_* cases that incorrectly returned E_CORE_* strings. Thanks josiebgoode.]

The following code expands on Vlad's code to show all the flags that are set. if not set, a blank line shows.

i<15;i < 15; i<15;i++ ) { print FriendlyErrorType($errLvl & pow(2, $i)) . "
\\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_COMPILE_ERROR: // 64 // return 'E_COMPILE_ERROR'; case E_COMPILE_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 ""; } ?>

`

bbrokman at gmail dot com

5 years ago

`A neat way to have a place in code to control error reporting configuration :)

FALSE, E_WARNING => TRUE, E_PARSE => TRUE, E_NOTICE => TRUE, E_CORE_ERROR => FALSE, E_CORE_WARNING => FALSE, E_COMPILE_ERROR => FALSE, E_COMPILE_WARNING => FALSE, E_USER_ERROR => TRUE, E_USER_WARNING => TRUE, E_USER_NOTICE => TRUE, E_STRICT => FALSE, E_RECOVERABLE_ERROR => TRUE, E_DEPRECATED => FALSE, E_USER_DEPRECATED => TRUE, E_ALL => FALSE, ];error_reporting( array_sum( array_keys($errorsActive, $search = true) ) );?>

`

fadhilinjagi at gmail dot com

3 years ago

`A simple and neat way to get the error level from the error code. You can even customize the error level names further.

"E_ERROR", E_WARNING => "E_WARNING", E_PARSE => "E_PARSE", E_NOTICE => "E_NOTICE", E_CORE_ERROR => "E_CORE_ERROR", E_CORE_WARNING => "E_CORE_WARNING", E_COMPILE_ERROR => "E_COMPILE_ERROR", E_COMPILE_WARNING => "E_COMPILE_WARNING", E_USER_ERROR => "E_USER_ERROR", E_USER_WARNING => "E_USER_WARNING", E_USER_NOTICE => "E_USER_NOTICE", E_STRICT => "E_STRICT", E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR", E_DEPRECATED => "E_DEPRECATED", E_USER_DEPRECATED => "E_USER_DEPRECATED", E_ALL => "E_ALL" ]; echo $exceptions["1"]; $code = 256; echo exceptions[exceptions[exceptions[code]; ?>

Output:
E_ERROR
E_USER_ERROR

This will need updating when PHP updates the error level names. Otherwise, it works just fine.

`

kezzyhko at NOSPAM dot semysha dot ru

8 years ago

`As for me, the best way to get error name by int value is that. And it's works fine for me ;)
<?php

array_flip

(array_slice(get_defined_constants(true)['Core'], 1, 15, true))[$type];//the same in readable form
array_flip(
array_slice(
get_defined_constants(true)['Core'],
1,
15,
true
)
)[$type]?>`

kaioker

3 years ago

`super simple error code to human readable conversion:

function prettycode($code){
return code==0?"FATAL":arraysearch(code == 0 ? "FATAL" : array_search(code==0?"FATAL":arraysearch(code, get_defined_constants(true)['Core']);
}

`

madcat34 at gmail dot com

1 month ago

`Since PHP 8.4.0:

E_STRICT (2048) has been removed.

E_ALL is now equal to 30719

`

ErikBachmann

5 years ago

`<?php
function getErrorTypeByValue($type) {
$constants = get_defined_constants(true);

foreach ( constants[′Core′]asconstants['Core'] as constants[Core]askey => $value ) { // Each Core constant
if ( preg_match('/^E_/', $key ) ) { // Check error constants
if ( type==type == type==value )
return( "$key=$value");
}
}
} // getErrorTypeByValue() echo "[".getErrorTypeByValue( 1 ) . "]". PHP_EOL;
echo "[".getErrorTypeByValue( 0 ) . "]". PHP_EOL;
echo "[".getErrorTypeByValue( 8 ) . "]". PHP_EOL;
?>

Will give
[E_ERROR=1]
[]
[E_NOTICE=8]`