in file1.php file:
set_error_handler('my_error_handler'); set_exception_handler('my_exception_handler'); function my_error_handler($errNo, $errStr, $errFile, $errLine, $whatever = null){ // here ErrFile and $errLine are correct only for native funcs... throw New ErrorException($errStr, 0, $errNo, $errFile, $errLine); } function my_exception_handler($exception){ print $exception->getLine(); // correct only for native functions print $exception->getFile(); // correct only for native functions }
in file2.php, an example of a function definition:
function foo($requiredArg){ }
and in the file 3.php, calling foo:
foo();
gives:
The argument 1 for foo () is missing, called in the file 3.php on line 2 and is defined ...
The message is useless, but when I try to get the file and line with $exception->getFile() and $exception->getLine() (in my exception handler), I get the file and the line where foo () was defined, and not there where he was called ...
But with native PHP functions, I get the file and the line where the function was called (and this is what I want).
source share