array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'exception.tostring.php', 1 => 'Exception::__toString', ), 'up' => array ( 0 => 'class.exception.php', 1 => 'Exception', ), 'prev' => array ( 0 => 'exception.gettraceasstring.php', 1 => 'Exception::getTraceAsString', ), 'next' => array ( 0 => 'exception.clone.php', 1 => 'Exception::__clone', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'language/predefined/exception/tostring.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5, PHP 7, PHP 8)
Exception::__toString — 将异常对象转换为字符串
此函数没有参数。
返回转换为字符串(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}