1

私たち全員がこの種の状況について異なる見解を持っているため、私のチームと議論した後.PHPエラーメッセージをオフにしたり、何らかの理由で警告をスローしているいくつかの関数を抑制したりすることが実際に許容されるのはいつですか..

実稼働環境では error_reporting をオフにする必要があると誰もが言っていることは理解していますが、それによって問題が解決されない問題が発生する可能性があります。したがって、何も修正されません。PHP には、エラー メッセージを制御するさまざまなメソッドが用意されています。例:

$Var = "Variable Is Set";

if (@$Var){ echo $Var; }

以上:

if (isset($Var)){ echo $Var; }

設定変数があるため、これは正常にエコーされます.一方、設定変数がない場合、これは通知をスローします..では、どちらを使用しますか? issetまたはエラー抑制?

また、実稼働環境では、どちらを使用するのがより適切でしょうか?

error_reporting(0);

上記は、すべてのタイプの PHP エラー報告をオフにし、何かが発生してもエラー メッセージを表示しません。そのため、場合によっては、メッセージが破棄されるため、未知の理由で動作を停止する壊れたコードにつながる可能性があります

また:

set_error_handler("");

上記により、ユーザーにエラーを適切に表示し、管理者が詳細な警告をログに記録できるようにするために使用できるカスタム エラー ハンドラが有効になります。 ?

それで私の全体的な質問は?

本番環境でエラーを処理するか、一般的にエラーをオフにしますか? これは、私が推測するベストプラクティスと好みに要約されます..

4

3 に答える 3

5

You never simply turn off error reporting entirely. You do turn off error display. Directly dumping errors to the screen is necessary during development (unless you have other methods which throw all errors in your face), in production you want the same error reporting but instead of it outputting visible errors, you want it to only log them. This can all be done using PHP's error reporting configuration settings.

If you want special custom error handling/logging, use a custom error handler.

As for @, you never write your application in a way that it produces actual errors on whose behavior you rely. You write everything in a way that does not trigger errors. You only use @ when there's no way to avoid a possible error because you cannot write it any other way, and you expect an error and are handling it; then all you do it to suppress the inevitable error message.

于 2013-06-16T16:39:33.573 に答える