This seems not to work when calling the PHP binary with the '-r' flag.
For example, if I run it like this:
php -r '
function exception_handler($exception) {
echo "Uncaught exception: " , $exception->getMessage(), "\n";
}
set_exception_handler("exception_handler");
throw new Exception("Uncaught Exception");
echo "Not Executed\n";
'
Or if I place it in a file and run it like this:
php -r 'include "./tmp.php";'
I get a stack trace instead of having the function 'exception_handler' called. If run it like this:
php tmp.php
It works fine.
(Why run code from '-r'? Sometimes it's useful to add stuff around the include like calls to microtime for benchmarks, or to include a library and then call a few functions from the library, all in an ad-hoc way without having to create new files.)
PHP versions 5.1.2 and 5.0.4.