&reftitle.examples; エラー処理機能を PHP で使用するための例を示します。 ファイルに(XML 形式で)情報を記録し、論理的に致命的なエラーの場合に、 開発者に電子メールを送信するようなエラー処理関数を定義します。 スクリプト内でのエラー処理 'Error', E_WARNING => 'Warning', E_PARSE => 'Parsing Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_STRICT => 'Runtime Notice', E_RECOVERABLE_ERROR => 'Catchable Fatal Error' ); // set of errors for which a var trace will be saved $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE); $err = "\n"; $err .= "\t" . $dt . "\n"; $err .= "\t" . $errno . "\n"; $err .= "\t" . $errortype[$errno] . "\n"; $err .= "\t" . $errmsg . "\n"; $err .= "\t" . $filename . "\n"; $err .= "\t" . $linenum . "\n"; if (in_array($errno, $user_errors)) { $err .= "\t" . wddx_serialize_value($vars, "Variables") . "\n"; } $err .= "\n\n"; // テスト用 // echo $err; // エラーログを保存し、重大なユーザーエラーは自分にメールする error_log($err, 3, "/usr/local/php4/error.log"); if ($errno == E_USER_ERROR) { mail("phpdev@example.com", "Critical User Error", $err); } } function distance($vect1, $vect2) { if (!is_array($vect1) || !is_array($vect2)) { trigger_error("Incorrect parameters, arrays expected", E_USER_ERROR); return NULL; } if (count($vect1) != count($vect2)) { trigger_error("Vectors need to be of the same size", E_USER_ERROR); return NULL; } for ($i=0; $i ]]>