PHP

PHP 开启或关闭错误提示

2020-04-26  本文已影响0人  887d1fc86fe6

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <?php
  // 在PHP文件最顶部加入开启错误提示代码
  ini_set("display_errors", "On"); 
  error_reporting(E_ALL | E_STRICT);

  // 错误的导入文件以及输出未定义的对象
  include 'lib/nav1.html';
  echo '<br>当前的页码为:' . $page;
  ?>
</body>
</html>
# 开发错误提示
display_errors = Off 修改为 display_errors = On

# 修改错误级别
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
修改为
error_reporting = E_ALL

在 php.ini 文件中的位置:

; This directive controls whether or not and where PHP will output errors,
; notices and warnings too. Error output is very useful during development, but
; it could be very dangerous in production environments. Depending on the code
; which is triggering the error, sensitive information could potentially leak
; out of your application such as database usernames and passwords or worse.
; For production environments, we recommend logging errors rather than
; sending them to STDOUT.
; Possible Values:
;   Off = Do not display any errors
;   stderr = Display errors to STDERR (affects only CGI/CLI binaries!)
;   On or stdout = Display errors to STDOUT
; Default Value: On
; Development Value: On
; Production Value: Off
; http://php.net/display-errors
# 开发错误提示
display_errors = Off // 修改为 display_errors = On

; Common Values:
;   E_ALL (Show all errors, warnings and notices including coding standards.)
;   E_ALL & ~E_NOTICE  (Show all errors, except for notices)
;   E_ALL & ~E_NOTICE & ~E_STRICT  (Show all errors, except for notices and coding standards warnings.)
;   E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR  (Show only errors)
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
; http://php.net/error-reporting
# 修改错误级别
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
// 修改为
error_reporting = E_ALL
上一篇下一篇

猜你喜欢

热点阅读