php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54275 Exception thrown in error_handler is swallowed
Submitted: 2011-03-16 16:23 UTC Modified: 2016-01-15 14:04 UTC
Votes:9
Avg. Score:4.9 ± 0.3
Reproduced:9 of 9 (100.0%)
Same Version:7 (77.8%)
Same OS:4 (44.4%)
From: v-o-e at gmx dot de Assigned: danack (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.5 OS: all
Private report: No CVE-ID: None
 [2011-03-16 16:23 UTC] v-o-e at gmx dot de
Description:
------------
Exception thrown in error_handler is swallowed if fatal error occurs after error in same instruction

somewhat related (closed) bugs:
http://bugs.php.net/bug.php?id=36773
http://bugs.php.net/bug.php?id=51463

Test script:
---------------
function error($code, $message, $file = null, $line = 0) {
	echo "convert error to exception<br>\n";
	throw new \ErrorException($message, $code, null, $file, $line);
}

function shutdown() {
	echo "shutdown function called<br>\n";
}

set_error_handler('error');
register_shutdown_function('shutdown');

try {
	echo $crypto->compress();
} catch (\Exception $e) {
	echo "exception catched<br>\n";
}

echo "after fatal error<br>\n";

Expected result:
----------------
exception should be catched as in (note the @ operator to suppress a FATAL ERROR!):

function error($code, $message, $file = null, $line = 0) {
	echo "convert error to exception<br>\n";
	throw new \ErrorException($message, $code, null, $file, $line);
}

function shutdown() {
	echo "shutdown function called<br>\n";
}

set_error_handler('error');
register_shutdown_function('shutdown');

try {
	echo @$crypto->compress();
} catch (\Exception $e) {
	echo "exception catched<br>\n";
}

echo "after fatal error<br>\n";

Actual result:
--------------
1. Exception thrown in error_handler is swallowed
2. the "fatal error" after "Undefined variable" occurs

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-17 11:18 UTC] mplomer at gmx dot de
I just downtracked the same problem. Additionally I have noticed that after the fatal error occours (after throwing the notice, which is swallowed), the shutdownFunction isn't called at all (tested on PHP 5.3.2).
When not throwing an error in error-handler, shutdownFunction is called properly.
 [2014-03-24 09:50 UTC] nicolas dot grekas+php at gmail dot com
Looks like this bug has been fixed in 5.5:
http://3v4l.org/JMsFv
 [2016-01-15 14:04 UTC] danack@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: danack
 [2016-01-15 14:04 UTC] danack@php.net
This was apparently fixed for PHP 5.5.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 15 17:01:29 2024 UTC