【问题标题】:how to disable the browser to give warning in php?如何禁用浏览器以在php中发出警告?
【发布时间】:2011-11-13 14:34:17
【问题描述】:

当某些东西被0除时,网页会出现这样的警告行“警告:C:\xampp\htdocs\XXXX.php第109行被零除”。我该如何解决这个问题。

谢谢

【问题讨论】:

  • 到目前为止,即使是这个星球上最聪明的人也无法解决这个问题

标签: php


【解决方案1】:

找到错误,然后修复它。

您不会抑制错误。

【讨论】:

    【解决方案2】:

    确保不要除以零。

    if( $divisor != 0 ) {
        $result = $number / $divisor;
    }
    else {
        $result = 0; // or print an error or whatever
    }
    

    【讨论】:

      【解决方案3】:

      你可以使用error_reporting函数......

         <?php
      
      // Turn off all error reporting
      error_reporting(0);
      
      // Report simple running errors
      error_reporting(E_ERROR | E_WARNING | E_PARSE);
      
      // Reporting E_NOTICE can be good too (to report uninitialized
      // variables or catch variable name misspellings ...)
      error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
      
      // Report all errors except E_NOTICE
      // This is the default value set in php.ini
      error_reporting(E_ALL ^ E_NOTICE);
      
      // Report all PHP errors (see changelog)
      error_reporting(E_ALL);
      
      // Report all PHP errors
      error_reporting(-1);
      
      // Same as error_reporting(E_ALL);
      ini_set('error_reporting', E_ALL);
      
      ?>
      

      【讨论】:

        【解决方案4】:

        首先,你必须避免这些错误,使用条件或异常 如果不可能,您可以禁用错误报告

        // Turn off all error reporting
        error_reporting(0);
        

        来源 - error_reporting

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-02-17
          • 1970-01-01
          • 2016-01-20
          • 1970-01-01
          • 2014-05-24
          • 2017-02-17
          相关资源
          最近更新 更多