PHP set_error_handler() 函数与 trigger_error() 函数的配合使用
2015-08-29 15:16
706 查看
两个函数的定义如下:
set_error_handler() 函数设置用户自定义的错误处理函数(注:是用户自定义的函数)
trigger_error() 函数创建用户定义的错误消息。(注:自定义的错误消息)
输出结果如下:
100
( ! ) Notice: Argument passed must be of type int in D:\www\MyProjecttest\index4.php on line 25
Call Stack
Time Memory Function Location
1 0.0000 135904 {main}( ) …\index4.php:0
2 0.0000 136384 test->project( string(10) ) …\index4.php:34
3 0.0000 136496 trigger_error ( string(35) ) …\index4.php:25
set_error_handler() 函数设置用户自定义的错误处理函数(注:是用户自定义的函数)
trigger_error() 函数创建用户定义的错误消息。(注:自定义的错误消息)
案例如下:
<?php function customError($errno, $errstr, $errfile,$errline){ return "<b>Custom Error:<b>[$errno]$errstr"."<br>"."Error on line $errline in $errfile"; } class test{ public function project($test){ if(is_int($test)){ return $test; }else{ trigger_error("Argument passed must be of type int"); } set_error_handler("customError"); } } $T=new test(); echo $T->project(100); echo $T->project("Helloworld"); ?>
输出结果如下:
100
( ! ) Notice: Argument passed must be of type int in D:\www\MyProjecttest\index4.php on line 25
Call Stack
Time Memory Function Location
1 0.0000 135904 {main}( ) …\index4.php:0
2 0.0000 136384 test->project( string(10) ) …\index4.php:34
3 0.0000 136496 trigger_error ( string(35) ) …\index4.php:25
相关文章推荐
- php-apc为magento加速
- php中$this、static、final、const、self 等几个关键字的用法
- set names解决中文乱码 php&sql
- 用phpStorm的数据库工具来管理你的数据库
- php学习01
- zend studio10破解
- 输出thinkphp中数据库操作对应的sql语句
- TAS5508 output changing
- STM8 PIN setting(output)
- 安装Stomp扩展时错误提示error: 'zend_class_entry' has no member named 'default_properties'
- ThinkPHP中使用ajax接收json数据的方法
- nusoap传递对象数组
- webservice——nusoap详解
- php小经验:解析preg_match与preg_match_all 函数
- php命名空间知识点
- php大力力 [035节] 先记录一些链接
- php5.4 的 arm 交叉编译
- 意识流php入门基础学习笔记
- vsftpd遇到“refusing to run with writable root inside chroot”错误
- PHPBONE使用问题集--.Net直接POST数据被过滤