• PHP错误级别处理,隐藏错误信息


    PHP错误级别处理,隐藏错误信息

    PHP错误级别:

    1.最低级别错误---Deprecated

    <?php
    
    //
    
    if(ereg('china','this is china',$matches)){
    
        print_r($matches);
    
    }else{
        echo 'not find';
    
    }

    2.通知级别错误---Notice(抛出报错信息,程序继续向下执行)

    <?php
    
    //不存在的变量
    
    echo $num;

    3.警告级别错误---Warning

    4.致命级别错误---Fatal(抛出报错信息,程序不能向下执行)

    5.语法解析错误---Parse(最高级别错误,程序不能执行)

    <?php
    
    echo md5(111);
    
    echo md6(1111);//不存在md6函数

    1.显示所有错误一:

    <?php
    
    //显示所有错误
    error_reporting(E_ALL&~E_NOTICE);
    
    //不显示所有错误
    error_reporting(0);
    
    //显示错误
    error_reporting(-1);
    
    
    //in_set() 运行时设置配置选项的值
    in_set('error_reporting',0);
    
    in_set('error_reporting',-1);

    in_set('display_errors',0);

    2.PHP错误处理:

    修改php.ini
    ;
    ; Error Level Constants:
    ; E_ALL             - All errors and warnings (includes E_STRICT as of PHP 5.4.0)
    ; E_ERROR           - fatal run-time errors
    ; E_RECOVERABLE_ERROR  - almost fatal run-time errors
    ; E_WARNING         - run-time warnings (non-fatal errors)
    ; E_PARSE           - compile-time parse errors
    ; E_NOTICE          - run-time notices (these are warnings which often result
    ;                     from a bug in your code, but it's possible that it was
    ;                     intentional (e.g., using an uninitialized variable and
    ;                     relying on the fact it's automatically initialized to an
    ;                     empty string)
    ; E_STRICT          - run-time notices, enable to have PHP suggest changes
    ;                     to your code which will ensure the best interoperability
    ;                     and forward compatibility of your code
    ; E_CORE_ERROR      - fatal errors that occur during PHP's initial startup
    ; E_CORE_WARNING    - warnings (non-fatal errors) that occur during PHP's
    ;                     initial startup
    ; E_COMPILE_ERROR   - fatal compile-time errors
    ; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
    ; E_USER_ERROR      - user-generated error message
    ; E_USER_WARNING    - user-generated warning message
    ; E_USER_NOTICE     - user-generated notice message
    ; E_DEPRECATED      - warn about code that will not work in future versions
    ;                     of PHP
    ; E_USER_DEPRECATED - user-generated deprecation warnings
    error_reporting = E_ALL&~E_NOTICR&E_DEPRECATED&~E_STRICT

    4.PHP通过trigger_error()触发PHP错误

    <?php
    
    header('content-type:text/html;charset=utf-8');
    
    $num1 = 1;
    $num2 = '3b';
    
    //判断$num1 和$num2 是否是合法数值
    if(!(is_numberic($num1)&& is_numeric($num2))){
    //trigger_error('num1 和 num2 必须为合法数值',E_USER_NOTICE); //
    trigger_error('num1 和 num2 必须为合法数值',E_USER_WARNING);
             trigger_error('num1 和 num2 必须为合法数值',E_USER_ERROR);

    }else{ echo $num1 + $num2 ; } echo '程序继续向下执行!';
  • 相关阅读:
    如何优化数据库中数据的查询
    2句sql语句的比较
    未来五年程序员应当具备的十项技能
    中小IT企业如何留住80后技术人才
    ORACLE的sign函数和DECODE函数
    Windows Server 2008系统 安装Oracle 10g 错误
    ORACLE 错误 ora01830 解决方法
    oracle instr函数
    Oracle 9i安装时没有找到OCS4J.properties 解决办法
    C# 中的委托和事件
  • 原文地址:https://www.cnblogs.com/ccw869476711/p/12846525.html
Copyright © 2020-2023  润新知