略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Exception::getFile

2024-04-24

Exception::getFile

(PHP 5, PHP 7, PHP 8)

Exception::getFile创建异常时的程序文件名称

说明

final public Exception::getFile(): string

获取创建异常的程序文件名称。

参数

此函数没有参数。

返回值

返回发生异常的程序文件名称。

范例

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

<?php
try {
    throw new 
Exception;
} catch(
Exception $e) {
    echo 
$e->getFile();
}
?>

以上例程的输出类似于:

/home/bjori/tmp/ex.php

参见

add a noteadd a note

User Contributed Notes 1 note

up
1
Jan
2 years ago
If you're looking to extract only the "ex.php" part of the full "/home/bjori/tmp/ex.php", then use:

<?php
   
echo basename($e->getFile())
?>

or better yet, esp. if your paths possibly contain non-ASCII characters:

<?php
   
echo pathinfo($e->getFile())['basename']
?>

官方地址:https://www.php.net/manual/en/exception.getfile.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3