PHP 自定义错误处理函数trigger_error()_PHP

WBOY
Release: 2016-06-01 12:07:57
Original
1045 people have browsed it

定义和用法trigger_error() 函数创建用户定义的错误消息。
trigger_error() 用于在用户指定的条件下触发一个错误消息。它与内建的错误处理器一同使用,也可以与由 set_error_handler() 函数创建的用户自定义函数使用。

如果指定了一个不合法的错误类型,该函数返回 false,否则返回 true。
语法trigger_error(error_message,error_types)
参数描述error_message必需。规定错误消息。长度限制为 1024 个字符。error_types可选。规定错误消息的错误类型。 可能的值: •E_USER_ERROR
•E_USER_WARNING
•E_USER_NOTICE
复制代码 代码如下:
function myError($errno,$errstr,$errfile,$errline){
switch($errno){
case E_USER_ERROR:
echo "My ERROR[$errno] $errstr
";
echo "Fatal error in line $errline of file $errfile";
exit(1);
break;
case E_USER_WARNING:
echo "My WARNING [$errno] $errstr";
break;
default:
echo "Unknown error type:[$errno] $errstr";
break;
}
}
set_error_handler("myError");
$age=-100;
if($agetrigger_error('age you input must>=0',E_USER_ERROR);
}
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!