1

この警告が抑制されたか、set_error_handler() 関数を使用していないかを確認する方法はありますか? @somethingwrong() と somethingwrong() のコードは 2 です。しかし、すべての警告をログに記録したくありません。たとえば、有効な入力データをテストする方法がないため、gzuncompress() などの一部の関数はこの方法で処理する必要があります。

$handler = new errorHandler();
error_reporting(0);
set_error_handler(array($handler, 'handle'));
set_exception_handler(array($handler, 'exception'));
register_shutdown_function(array($handler, 'shutdown'));

class errorHandler
{
public function handle($code, $text, $file, $line)
{
    if (($code & (E_STRICT | E_NOTICE)) == 0)
        $this->log(...);
}

public function exception($exception)
{
    ...
}

public function shutdown()
{
    $e = error_get_last();
    if ($e !== NULL)
        $this->log($error);
}
}

// the errors
include('notexisting.file'); // should be logged
@gzuncompress('somenonsens'); // should not be logged
4

2 に答える 2

0

試してみましたか?@gzuncompress のように @ を使用すると、通常の警告は表示されず、エラー ハンドラも呼び出されないと思います。

于 2013-05-14T14:31:19.930 に答える