• 技术文章 >php教程 >php手册

    php 错误报告开启详细实现

    2016-06-13 09:54:59原创546
    php教程 错误报告开启详细实现

    定义和用法
    error_reporting() 设置 php 的报错级别并返回当前级别。

    语法
    error_reporting(report_level)如果参数 level 未指定,当前报错级别将被返回。下面几项是 level 可能的值

    */
    //关闭所有的错误报告
    error_reporting(0);
    //只报告运行错误
    error_reporting(e_error|e_warning|e_parse);
    //报告e_notice
    error_reporting(e_error|e_warning|e_parse|e_notice);
    //报告所有的运行错误,除了e_notice
    //这是php.ini的默认值
    error_reporting(e_all ^ e_notice);
    //报告所有的php错误
    error_reporting(e_all);
    //和error_reporting(e_all)有一样的功效,该设置也会报告所有php错误
    ini_set('error_reporting', e_all);

    /*

    值 常量 描述
    1 e_error fatal run-time errors. errors that can not be recovered from. execution of the script is halted
    2 e_warning non-fatal run-time errors. execution of the script is not halted
    4 e_parse compile-time parse errors. parse errors should only be generated by the parser
    8 e_notice run-time notices. the script found something that might be an error, but could also happen when running a script normally
    16 e_core_error fatal errors at php startup. this is like an e_error in the php core
    32 e_core_warning non-fatal errors at php startup. this is like an e_warning in the php core
    64 e_compile_error fatal compile-time errors. this is like an e_error generated by the zend scripting engine
    128 e_compile_warning non-fatal compile-time errors. this is like an e_warning generated by the zend scripting engine
    256 e_user_error fatal user-generated error. this is like an e_error set by the programmer using the php function trigger_error()
    512 e_user_warning non-fatal user-generated warning. this is like an e_warning set by the programmer using the php function trigger_error()
    1024 e_user_notice user-generated notice. this is like an e_notice set by the programmer using the php function trigger_error()
    2048 e_strict run-time notices. php suggest changes to your code to help interoperability and compatibility of the code
    4096 e_recoverable_error catchable fatal error. this is like an e_error but can be caught by a user defined handle (see also set_error_handler())
    8191 e_all all errors and warnings, except level e_strict (e_strict will be part of e_all as of php 6.0)

    */

    function unserialize_handler($errno,$errstr) //自定义函数
    {
    echo "invalid serialized value.n"; //输出指定内容
    }
    $serialized='foo'; //定义字符串
    set_error_handler('unserialize_handler'); //设置用户自定义错误信息函数
    $original=unserialize($serialized); //从已存储的表示中创建php的值
    restore_error_handler(); //恢复错误信息指针

    php入门到就业线上直播课:查看学习

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

    前端(VUE)零基础到就业课程:点击学习

    清晰的学习路线+老师随时辅导答疑

    自己动手写 PHP MVC 框架:点击学习

    快速了解MVC架构、了解框架底层运行原理

    上一篇:php mb_strlen()中英混体字符截取代码 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • ❤️‍🔥共22门课程,总价3725元,会员免费学• ❤️‍🔥接口自动化测试不想写代码?• Yii2如何批量添加数据,Yii2批量添加数据• php+mysqli预处理技术实现添加、修改及删除多条数据的方法,mysqli多条• php+mysql实现数据库随机重排实例,phpmysql重排实例• PHP类中的魔术方法(Magic Method)简明总结,magicmethod• ThinkPHP3.1的Widget新用法
    1/1

    PHP中文网