note 111484 modified in function.set-exception-handler by danbrown
| From: | danbrown@php.net | Date: | Mon, 04 Mar 2013 17:52:22 +0000 |
| Subject: | note 111484 modified in function.set-exception-handler by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193839@lists.php.net to get a copy of this message | ||
As of PHP 5.4.11....
Instead of:
Output: Fatal error: Exception thrown without a stack frame in Unknown on line 0
This snippet:
<?php
function error_handler($code, $message, $file, $line)
{
if (0 == error_reporting())
{
return;
}
throw new ErrorException($message, 0, $code, $file, $line);
}
function exception_handler($e)
{
// ... normal exception stuff goes here
print $undefined; // This is the underlying problem
}
set_error_handler("error_handler");
set_exception_handler("exception_handler");
throw new Exception("Just invoking the exception handler");
?>
Now returns:
Fatal error: Uncaught exception 'ErrorException' with message 'Undefined variable:
undefined' in C:\Apache2\htdocs\error\test.php:13 Stack trace: #0
C:\Apache2\htdocs\error\test.php(13): error_handler(8, 'Undefined varia...',
'C:\Apache2\htdo...', 13, Array) #1 [internal function]:
exception_handler(Object(Exception)) #2 {main} thrown in C:\Apache2\htdocs\error\test.php on line 13
So it appears that exceptions thrown within exception handler now bypass exception handler.
--was--
As of PHP 5.4.11, throwing an exception within the exception handler will no longer behave the way
joshua and others had pointed out.
Instead of:
Output: Fatal error: Exception thrown without a stack frame in Unknown on line 0
This snippet:
<?php
function error_handler($code, $message, $file, $line)
{
if (0 == error_reporting())
{
return;
}
throw new ErrorException($message, 0, $code, $file, $line);
}
function exception_handler($e)
{
// ... normal exception stuff goes here
print $undefined; // This is the underlying problem
}
set_error_handler("error_handler");
set_exception_handler("exception_handler");
throw new Exception("Just invoking the exception handler");
?>
Now returns:
Fatal error: Uncaught exception 'ErrorException' with message 'Undefined variable:
undefined' in C:\Apache2\htdocs\error\test.php:13 Stack trace: #0
C:\Apache2\htdocs\error\test.php(13): error_handler(8, 'Undefined varia...',
'C:\Apache2\htdo...', 13, Array) #1 [internal function]:
exception_handler(Object(Exception)) #2 {main} thrown in C:\Apache2\htdocs\error\test.php on line 13
So it appears that exceptions thrown within exception handler now bypass exception handler.
http://php.net/manual/en/function.set-exception-handler.php