ErrorException::getSeverity

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

ErrorException::getSeverity获取异常严重性

说明

final public ErrorException::getSeverity(): int

返回异常的严重性。

参数

此函数没有参数。

返回值

返回异常的严重级别。

范例

范例 #1 ErrorException::getSeverity() 范例

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

上面的例子将输出类似于

This exception severity is: 256
bool(true)

添加注释

用户贡献的注释 2 个注释

fgaab
14 年前
尝试使用此作为 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");
?>
cyjimmy264 at gmail dot com
7 年前
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);
}
To Top