PHP 8.3.4 Released!

ErrorException::getSeverity

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

ErrorException::getSeverityİstisnanın önem derecesi ile döner

Açıklama

final public ErrorException::getSeverity(): int

İstisnanın önem derecesini döndürür.

Bağımsız Değişkenler

Bu işlevin bağımsız değişkeni yoktur.

Dönen Değerler

İstisnanın önem derecesini döndürür.

Örnekler

Örnek 1 - ErrorException::getSeverity() örneği

<?php
try {
throw new
ErrorException("İstisna iletisi", 0, E_USER_ERROR);
} catch(
ErrorException $e) {
echo
"Bu istisnanın önem derecesi: " . $e->getSeverity();
var_dump($e->getSeverity() === E_USER_ERROR);
}
?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

Bu istisnanın önem derecesi: 256
bool(true)

add a note

User Contributed Notes 2 notes

up
0
cyjimmy264 at gmail dot com
6 years ago
function friendly_severity($severity) {
$names = [];

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

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

return join(' | ', $names);
}
up
0
fgaab
14 years ago
Try this as replacement for error_reporting(...)

<?php
function exception_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->getSeverity() & $severity) != 0) {
throw
$ex;
}
}
set_error_handler("exception_error_handler");
?>
To Top