Exception::__toString

(PHP 5, PHP 7, PHP 8)

Exception::__toString將異常對象轉(zhuǎn)換為字符串

說明

public Exception::__toString(): string

返回轉(zhuǎn)換為字符串(string)類型的異常。

參數(shù)

此函數(shù)沒有參數(shù)。

返回值

返回轉(zhuǎn)換為字符串(string)類型的異常。

范例

示例 #1 Exception::__toString()示例

<?php
try {
    throw new 
Exception("Some error message");
} catch(
Exception $e) {
    echo 
$e;
}
?>

以上例程的輸出類似于:

exception 'Exception' with message 'Some error message' in /home/bjori/tmp/ex.php:3
Stack trace:
#0 {main}

參見