From: crocodile2u at gmail dot com
Operating system: Ubuntu 8.10
PHP version: 5.3.0beta1
PHP Bug Type: Scripting Engine problem
Bug description: autoloading classes inside exception_handler leads to crashes
Description:
------------
When I use set_exception_handler() and attempt to create an instance of a
class inside the handler (the class is not yet loaded and needs to be
loaded with __autoload) - I get crashes.
The crash type depends on whether I use __autoload() or
spl_autoload_register(). I the first case I get "Fatal error: Exception
thrown without a stack frame in Unknown on line 0", while in the second I
get "Fatal error: Allowed memory size of 134217728 bytes exhausted (tried
to allocate 72 bytes) in /home/vbolshov/tmp/x.php on line 21
Segmentation fault"
It must be noticed, that in case the class already had been loaded by the
moment of the exception throw - there are no errors and everything is ok.
I am terribly sorry the the reproduce code is longer than 20 lines but it
is really simple and I think it shows all the problems.
Reproduce code:
---------------
<?php
/*
Uncomment handler class declaration to get rid of crashes
*/
/*
class handler {
function handle($e) {
echo $e->getMessage()."\n";
}
}
*/
function au($class) {
eval('class handler {
function handle($e) {
echo $e->getMessage()."\n";
}
}');
}
/*
Uncomment __autoload() and comment spl_autoload_register() call to switch
between crash types
*/
/*
function __autoload($class) {
au($class);
}
*/
spl_autoload_register('au');
set_exception_handler(function($exception) {
$h = new handler();
$h->handle($exception);
});
throw new Exception('exception');
Expected result:
----------------
exception
Actual result:
--------------
In case we use spl_autoload_register:
--
Fatal error: Exception thrown without a stack frame in Unknown on line 0
--
In case we use __autoload:
--
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to
allocate 72 bytes) in /home/vbolshov/tmp/x.php on line 21
Segmentation fault
--
Works ok when handler class declaration at the top is uncommented.
--
Edit bug report at http://bugs.php.net/?id=47714&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=47714&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=47714&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=47714&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=47714&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=47714&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=47714&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=47714&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=47714&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=47714&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=47714&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=47714&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=47714&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=47714&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=47714&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47714&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47714&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=47714&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=47714&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=47714&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=47714&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=47714&r=mysqlcfg