array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'exception.getline.php', 1 => 'Exception::getLine', ), 'up' => array ( 0 => 'class.exception.php', 1 => 'Exception', ), 'prev' => array ( 0 => 'exception.getfile.php', 1 => 'Exception::getFile', ), 'next' => array ( 0 => 'exception.gettrace.php', 1 => 'Exception::getTrace', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'language/predefined/exception/getline.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5, PHP 7, PHP 8)
Exception::getLine — 获取创建的异常所在文件中的行号
此函数没有参数。
返回发生异常的代码在文件中的行号。
示例 #1 Exception::getLine()示例
<?php
try {
throw new Exception("Some error message");
} catch(Exception $e) {
echo "The exception was thrown on line: " . $e->getLine();
}
?>
以上示例的输出类似于:
The exception was thrown on line: 3