From:
Operating system: Windows
PHP version: 5.3.2
Package: Scripting Engine problem
Bug Type: Bug
Bug description:ErrorException thrown from error_handler not catchable in
exception handler
Description:
------------
It seems that there are some cases, when you can't catch Exceptions with
exception_handler which was thrown from error_handler for some errors.
For example if you do this:
$class = new StdClass;
echo $class->$foo;
error_handler gets called, ErrorException was thrown, but the Exception
wasn't catched with the exception_handler.
if you try
echo $foo;
instead of
echo $class->$foo;
then the "same" error gets called with the error handler (by same error, I
mean same parameters), but the Exception thrown in this case is successfuly
catched by the exception handler.
Test script:
---------------
<?php
error_reporting(E_ALL);
ini_set('display_errors', 0);
function debug($s){
echo "<pre>";
var_dump($s);
echo "</pre>";
}
set_error_handler(
function ($errno, $errstr, $errfile, $errline ) {
debug('error_handler');
debug(array(
'errno' => $errno,
'errstr' => $errstr,
'errfile' => $errfile,
'errline' => $errline,
));
throw new ErrorException($errstr, 0, $errno, $errfile,
$errline);
}
);
set_exception_handler(
function(Exception $e){
debug('exception_handler');
debug($e);
}
);
$class = new StdClass;
echo $class->$foo;
echo 'done';
Expected result:
----------------
string(13) "error_handler"
array(4) {
["errno"]=>
int(8)
["errstr"]=>
string(23) "Undefined variable: foo"
["errfile"]=>
string(55) "C:\work\xampp_vc9\htdocs\default\bug\error_handling.php"
["errline"]=>
int(46)
}
string(17) "exception_handler"
object(ErrorException)#4 (8) {
["message":protected]=>
string(23) "Undefined variable: foo"
...
Actual result:
--------------
string(13) "error_handler"
array(4) {
["errno"]=>
int(8)
["errstr"]=>
string(23) "Undefined variable: foo"
["errfile"]=>
string(55) "C:\work\xampp_vc9\htdocs\default\bug\error_handling.php"
["errline"]=>
int(46)
}
--
Edit bug report at http://bugs.php.net/bug.php?id=51463&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=51463&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=51463&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=51463&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=51463&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=51463&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=51463&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=51463&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=51463&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=51463&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=51463&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=51463&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=51463&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=51463&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=51463&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51463&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=51463&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=51463&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=51463&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=51463&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=51463&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=51463&r=mysqlcfg