PHP 8.3.4 Released!

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 note

User Contributed Notes 1 note

up
-1
Jan
4 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']
?>
To Top