ホームページ  >  記事  >  バックエンド開発  >  PHPエラーレベル設定と原理分析

PHPエラーレベル設定と原理分析

不言
不言オリジナル
2018-05-04 10:02:541469ブラウズ

この記事では、主に PHP のエラー レベルの設定と原則の分析を紹介します。これには、必要な友達が参考にできるようにします。

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

上記の構成では:

、すべての通知、警告、エラー情報を表示することを意味します (コーディング標準を含むすべてのエラー、警告、および通知を表示します)。

PHP マニュアルの定義済み定数で詳しく説明されており、以下はその抜粋です: error_reporting为设置配置级别;默认是E_ALL

例: E_ALL & ~E_NOTICE
E_ALL: 111011111111111

E_通知: 1000
~E_通知: 0111
E_ALL & ~E_NOTICE: 111011111110111

phpはバイナリ変換を通じてエラーレベルを制御する方法です。

エラー レベルを調整します

グローバル設定

効果を実現するには、php.ini ファイルの error_reporting を変更します。

例:

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>rrreee

ローカル設定

スクリプトまたはプログラムでは、ini_set() および error_reporting() 設定を通じて効果を実現できます。 例:

🎜rrreee🎜関連する推奨事項: 🎜🎜<a href="http://www.php.cn/php-weizijiaocheng-392917.html" target="_self ">PHP エラー報告と自動ジャンプ🎜</a>🎜🎜🎜開発モードと製品モードでの PHP エラー処理🎜🎜

以上がPHPエラーレベル設定と原理分析の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。