php錯誤控制運算子

來源:互聯網
上載者:User
PHP 支援一個錯誤控制運算子:@。當將其放置在一個 PHP 運算式之前,該運算式可能產生的任何錯誤資訊都被忽略掉。

如果用 set_error_handler() 設定了自訂的錯誤處理函數,仍然會被調用,但是此錯誤處理函數可以(並且也應該)調用 error_reporting(),而該函數在出錯語句前有 @ 時將返回 0。

如果啟用了 track_errors 特性,運算式所產生的任何錯誤資訊都被存放在變數 $php_errormsg 中。此變數在每次出錯時都會被覆蓋,所以如果想用它的話就要儘早檢查。

<?php/* Intentional file error */$my_file = @file ('non_existent_file') or    die ("Failed opening file: error was '$php_errormsg'");// this works for any expression, not just functions:$value = @$cache[$key];// will not issue a notice if the index $key doesn't exist.?>

Note: @ 運算子只對錶達式有效。對新手來說一個簡單的規則就是:如果能從某處得到值,就能在它前面加上 @ 運算子。例如,可以把它放在變數,函數和 include 調用,常量,等等之前。不能把它放在函數或類的定義之前,也不能用於條件結構例如 if 和 foreach 等。

Warning

[email protected]��[email protected]�[email protected]��來抑制錯誤資訊,那指令碼會沒有任何跡象顯示原因而死在那裡。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.