ホームページ  >  記事  >  バックエンド開発  >  php_PHP チュートリアルの error_reporting 関数の使用方法の詳細な説明

php_PHP チュートリアルの error_reporting 関数の使用方法の詳細な説明

WBOY
WBOYオリジナル
2016-07-13 17:00:111289ブラウズ

phpでは、error_reportingはPHPのエラーレベルを設定し、現在のレベルを返すもので、ドメイン外でエラーが発生した場合にエラープロンプトを表示するか、プログラムを実行するかをレベルに応じて設定できます。 error_reporting() の使用法とパラメータ。

基本情報

E_NOTICE は、通常の状況が記録されないことを意味し、存在しない変数にアクセスしようとしたり、存在しないファイルを表示するために stat() 関数を呼び出したりするなど、プログラムにエラーが発生した場合にのみ使用されます。
通常、E_WARNING が表示されますが、プログラムの実行は中断されません。これはデバッグに役立ちます。たとえば、問題の正規表現を使用して ereg() を呼び出します。
通常は E_ERROR が表示され、プログラムの実行が中断されます。これは、このマスクを使用してメモリ構成やその他のエラーを追跡できないことを意味します。
E_PARSE 構文の解析エラー。
E_CORE_ERROR E_ERROR と似ていますが、PHP コアによって引き起こされるエラーは除外されます。
E_CORE_WARNING E_WARNING と似ていますが、PHP コア エラー警告は含まれません。

例:

error_reporting = E_ALL & ~E_NOTICE ; リマインダーを除くすべてのエラーを表示します
error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR ; エラーのみが表示されます

error_reporting=E_ERROR: 致命的なエラーのみが報告されます

基本的なセットアップ

error_reporting = E_ALL & ~E_NOTICE ; リマインダーを除くすべてのエラーを表示します


コードは次のとおりです コードをコピー


エラー報告(0);

// 単純な実行エラーを報告します
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// E_NOTICE を報告するのも良いでしょう (初期化されていないことを報告するには
) // 変数、または変数名のスペルミスをキャッチする ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// E_NOTICE を除くすべてのエラーを報告します
// これはphp.iniに設定されているデフォルト値です
error_reporting(E_ALL ^ E_NOTICE);

// すべての PHP エラーを報告します (PHP 3 ではビット単位 63 が使用される可能性があります)
エラー報告(E_ALL);

// error_reporting(E_ALL);
と同じ ini_set('error_reporting', E_ALL);

整数。古いPHPのエラーレベルを表します。 (古い error_reporting レベルを返します。)
マニュアルの例:

PHP 5.2.x および以前の 2047 では 6143
Value Constant Description Note
1 E_ERROR (integer) Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted.  
2 E_WARNING (integer) Run-time warnings (non-fatal errors). Execution of the script is not halted.  
4 E_PARSE (integer) Compile-time parse errors. Parse errors should only be generated by the parser.  
8 E_NOTICE (integer) Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.  
16 E_CORE_ERROR (integer) Fatal errors that occur during PHP’s initial startup. This is like an E_ERROR, except it is generated by the core of PHP. since PHP 4
32 E_CORE_WARNING (integer) Warnings (non-fatal errors) that occur during PHP’s initial startup. This is like an E_WARNING, except it is generated by the core of PHP. since PHP 4
64 E_COMPILE_ERROR (integer) Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine. since PHP 4
128 E_COMPILE_WARNING (integer) Compile-time warnings (non-fatal errors). This is like an E_WARNING, except it is generated by the Zend Scripting Engine. since PHP 4
256 E_USER_ERROR (integer) User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error(). since PHP 4
512 E_USER_WARNING (integer) User-generated warning message. This is like an E_WARNING, except it is generated in PHP code by using the PHP function trigger_error(). since PHP 4
1024 E_USER_NOTICE (integer) User-generated notice message. This is like an E_NOTICE, except it is generated in PHP code by using the PHP function trigger_error(). since PHP 4
2048 E_STRICT (integer) Run-time notices. Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code. since PHP 5
4096 E_RECOVERABLE_ERROR (integer) Catchable fatal error. It indicates that a probably dangerous error occured, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle (see also set_error_handler()), the application aborts as it was an E_ERROR. PHP 5.2.0以降
8191 E_ALL (整数) PHP 6 未満のレベル E_STRICT を除くすべてのエラーと警告。

http://www.bkjia.com/PHPjc/631263.htmlwww.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/631263.html技術記事 php では、error_reporting は PHP のエラー レベルを設定し、現在のレベルを返すために、エラー プロンプトを表示しないかどうか、ドメイン外でエラーが発生した場合にプログラムを実行するかどうかをさまざまなレベルに応じて設定できます。
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。