PHP 오류 수준 설정 및 원리 분석

不言
풀어 주다: 2023-03-25 11:04:01
원래의
1478명이 탐색했습니다.

이 글은 주로 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 is 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;
; 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-reportingerror_reporting = E_ALL
로그인 후 복사

위 구성에서 error_reporting은 구성 수준을 설정하는 것입니다. 기본값은 E_ALL입니다. 이는 모든 알림, 경고, 오류 정보(코딩 표준을 포함한 모든 오류, 경고 및 알림을 표시합니다.)
PHP 매뉴얼의 사전 정의된 상수에 대한 자세한 설명이 있습니다. 다음은 발췌 부분입니다:
error_reporting为设置配置级别;默认是E_ALL,意思显示所有Notice,Warning,Error信息(Show all errors, warnings and notices including coding standards.)。
在PHP手册预定义常量中有详细解释,下面为摘录的一部分:

例子:E_ALL & ~E_NOTICE
E_ALL: 111011111111111
E_NOTICE: 1000
~E_NOTICE: 0111
E_ALL & ~E_NOTICE:111011111110111

php就是这样通过二进制的转换来控制错误级别的。

调整错误级别

全局设置

更改php.ini文件中的error_reporting就可以达到效果。
例如:

1. error_reporting = E_ALL #输出所有错误,警告,notice信息
2. error_reporting = E_ALL & ~E_NOTICE #输出所有错误和警告信息,不输出notice信息
3. E_ALL & ~E_NOTICE & ~E_WARNING #输出所有错误信息,不输出警告,notice信息
로그인 후 복사

局部设置

在脚本或程序中,通过ini_set()和error_reporting()设置可以达到效果。
例如:

ini_set("display_errors",1)
error_reporting(E_ALL)
로그인 후 복사

相关推荐:

<a href="http://www.php.cn/php-weizijiaocheng-392917.html" target="_self">PHP报错并自动跳转</a>

예: E_ALL & ~E_NOTICE
E_ALL: 1110111111111111
E_NOTICE: 1000
~E_NOTICE: 0111
E_ALL & ~E_NOTICE: 111011111110111

php는 바이너리 변환을 통해 오류 수준을 제어하는 ​​방법입니다. 오류 수준을 조정하세요🎜

전역 설정

🎜효과를 얻으려면 php.ini 파일에서 error_reporting을 변경하세요.
예:
🎜rrreee

로컬 설정

🎜스크립트나 프로그램에서 ini_set() 및 error_reporting() 설정을 통해 효과를 얻을 수 있습니다.
예:
🎜rrreee🎜관련 권장 사항:🎜🎜<a href="http://www.php.cn/php-weizijiaocheng-392917.%20html%20" target="_self">PHP 오류 보고 및 자동 점프🎜</a>🎜🎜🎜개발 모드 및 제품 모드에서 PHP 오류 처리🎜🎜

위 내용은 PHP 오류 수준 설정 및 원리 분석의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!