PHP trigger_error() 函數(shù)
PHP trigger_error() 函數(shù)
定義和用法
trigger_error() 函數(shù)創(chuàng)建用戶自定義的錯(cuò)誤消息。
trigger_error() 函數(shù)用于在用戶指定的條件下觸發(fā)一個(gè)錯(cuò)誤消息。它可以與內(nèi)建的錯(cuò)誤處理程序一起使用,或者與由 set_error_handler() 函數(shù)設(shè)置的用戶自定義函數(shù)一起使用。
當(dāng)您需要在運(yùn)行腳本時(shí)的某個(gè)指定條件下自定義錯(cuò)誤消息時(shí),該函數(shù)很有用。
如果指定了一個(gè)不合法的錯(cuò)誤類型,該函數(shù)返回 FALSE,否則返回 TRUE。
語法
trigger_error(error_message,error_types)
參數(shù) | 描述 |
---|---|
error_message | 必需。規(guī)定錯(cuò)誤消息。長度限制為 1024 個(gè)字符。 |
error_types | 可選。規(guī)定錯(cuò)誤消息的錯(cuò)誤類型。 可能的錯(cuò)誤類型:
|
實(shí)例
<?php $test=2; if ($test>1) { trigger_error("A custom error has been triggered"); } ?>
上面代碼的輸出如下所示:
Notice: A custom error has been triggered
in C:webfoldertest.php on line 6
in C:webfoldertest.php on line 6
相關(guān)文章
- PHP EOF(heredoc) 使用說明
- PHP 字符串
- PHP 命名空間 namespace
- PHP 面向?qū)ο?/a>
- PHP date() 函數(shù)
- PHP JSON
- PHP array_diff_ukey() 函數(shù)
- PHP array_map() 函數(shù)
- PHP array_rand() 函數(shù)
- PHP array_reduce() 函數(shù)
- PHP array_search() 函數(shù)
- PHP array_uintersect_assoc() 函數(shù)
- PHP arsort() 函數(shù)
- PHP compact() 函數(shù)
- PHP end() 函數(shù)
- PHP rsort() 函數(shù)
- PHP shuffle() 函數(shù)
- PHP usort() 函數(shù)
- PHP FTP 函數(shù)
- PHP 5 Math 函數(shù)