Exception::getFile

(PHP 5, PHP 7, PHP 8)

Exception::getFileObtém o arquivo no qual a exceção ocorreu

Descrição

final public Exception::getFile ( ) : string

Obtém o nome do arquivo de onde a exceção foi criada.

Parâmetros

Esta função não possui parâmetros.

Valor Retornado

Retorna o nome do arquivo no qual a exceção foi criada.

Exemplos

Exemplo #1 Exemplo da Exception::getFile()

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

O exemplo acima irá imprimir algo similar à:

/home/bjori/tmp/ex.php

Veja Também

add a note 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