trigger_errror 定义如下:
trigger_error() 函数创建用户定义的错误消息。
trigger_error() 用于在用户指定的条件下触发一个错误消息。它与内建的错误处理器一同使用,也可以与由 set_error_handler() 函数创建的用户自定义函数使用。
如果指定了一个不合法的错误类型,该函数返回 false,否则返回 true。
实例如下:
function testPrimitive($str){
if(is_string($str)){
return $x=$str."world";
}else{
return trigger_error("Argument passed must be of type string");
}
}
echo testPrimitive('Hello');
echo testPrimitive(1);
输出结果如下:
Helloworld
( ! ) Notice: Argument passed must be of type string in D:\www\MyProjecttest\index4.php on line 20
Call Stack
Time Memory Function Location
1 0.0156 132440 {main}( ) …\index4.php:0
2 0.0156 132768 testPrimitive( long ) …\index4.php:25
3 0.0156 132880 trigger_error ( string(38) ) …\index4.php:20