php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47714 autoloading classes inside exception_handler leads to crashes
Submitted: 2009-03-19 08:33 UTC Modified: 2009-03-26 10:57 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: crocodile2u at gmail dot com Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.0beta1 OS: Ubuntu 8.10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: crocodile2u at gmail dot com
New email:
PHP Version: OS:

 

 [2009-03-19 08:33 UTC] crocodile2u at gmail dot com
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-19 08:36 UTC] crocodile2u at gmail dot com
> 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"

I am sorry but the error messages are mixed up here. 

Correct is:
for __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"
for spl_autoload_register(): "Fatal error: Exception
thrown without a stack frame in Unknown on line 0"
 [2009-03-20 00:56 UTC] felipe@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-03-20 06:12 UTC] crocodile2u at gmail dot com
All the same with this snapshot. Both crashes remain.
 [2009-03-25 11:33 UTC] saschagros at gmail dot com
I can confirm this.

I am testing Drupal on PHP 5.3 and I am getting the same "Fatal error: Exception
thrown without a stack frame in Unknown on line 0" in our exception_handler test, because we creat a new object (to log exceptions) in the exception handler function.
 [2009-03-26 10:57 UTC] dmitry@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 16:01:27 2024 UTC