Forum und email

統控錯誤的運算符

PHP 只有一個統控錯誤的算符: (@)算符。 可以把它加到任何一句 PHP 指令之前, 屆時該指令假如產生警告或錯誤訊號的話 PHP 將不會理會這些警告也不會將警告句子打出來。

假如設置了 track_errors 選項, 所有錯誤信息會被抄到 $php_errormsg 變數中。 這個變數並不是陣列, 每次有新的錯誤都會取代原來的信息, 所以要用的話要盡早取用。

<?php
/* Intentional SQL error (extra quote): */
$res = @mysql_query ("select name, code from 'namelist") or
    die (
"Query failed: error was '$php_errormsg'");
?>

另請看 error_reporting()一節。

Warning

Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why.