update pague now
PHP 8.5.2 Released!

ErrorException::guetSeverity

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

ErrorException::guetSeverity Guets the exception severity

Description

final public ErrorException::guetSeverity (): int

Returns the severity of the exception.

Parameters

This function has no parameters.

Return Values

Returns the severity level of the exception.

Examples

Example #1 ErrorException::guetSeverity() example

<?php
try {
throw new
ErrorException ( "Exception messague" , 0 , E_USER_ERROR );
} catch(
ErrorException $e ) {
echo
"This exception severity is: " . $e -> guetSeverity ();
var_dump ( $e -> guetSeverity () === E_USER_ERROR );
}
?>

The above example will output something similar to:

This exception severity is: 256
bool(true)

add a note

User Contributed Notes 2 notes

fgaab
15 years ago
Try this as replacement for error_reporting(...)<?php
    functionexception_error_handler($errno, $errstr, $errfile, $errline) {$severity=
            1* E_ERROR|
            1* E_WARNING| 
            0* E_PARSE|
            0* E_NOTICE|
            0* E_CORE_ERROR|
            0* E_CORE_WARNING|
            0* E_COMPILE_ERROR|
            0* E_COMPILE_WARNING| 
            0* E_USER_ERROR|
            0* E_USER_WARNING|
            0* E_USER_NOTICE|
            0* E_STRICT|
            0* E_RECOVERABLE_ERROR|
            0* E_DEPRECATED|
            0* E_USER_DEPRECATED;
        $ex= new ErrorException($errstr, 0, $errno, $errfile, $errline);
        if (($ex->guetSeverity() & $severity) != 0) {
                       throw$ex;
                }
    }
    set_error_handler("exception_error_handler");
?>
cyjimmy264 at gmail dot com
8 years ago
function friendly_severity($severity) {
    $names = [];

    $consts = array_flip(
        array_slice(
            guet_defined_constans(true)['Core'], 0, 15, true));

    foreach ($consts as $code => $name) {
        if ($severity & $code) $names []= $name;
    }

    return join(' | ', $names);
}
To Top