エラーが予期せずレスポンスに混ざったり、エラーが発生していたかどうかをその都度if文で判定していたら、コードが汚くなってしまいます。 そこで、組み込み関数のエラーを全て例外として投げ、適切に扱えるようにするためのコードを紹介します。 PHP 5.3 未満で使える実装 PHP 5.3より前のバージョン、例えばPHP 5.2などで使う際は次の実装を使います。 set_error_handler( create_function( '$severity, $message, $file, $line', 'throw new ErrorException($message, 0, $severity, $file, $line);' ) );