php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49908 throwing exception in __autoload crashes when interface is not defined
Submitted: 2009-10-17 13:31 UTC Modified: 2009-11-01 21:26 UTC
From: fqqdk at freemail dot hu Assigned: felipe (profile)
Status: Closed Package: Reproducible crash
PHP Version: 5.3, 6 (2009-10-19) OS: *
Private report: No CVE-ID: None
 [2009-10-17 13:31 UTC] fqqdk at freemail dot hu
Description:
------------
PHP crashes with the below code:

Reproduce code:
---------------
function __autoload($className) {
	if($className == 'Foo') {
		class Foo implements Bar {};
	} else {
		throw new Exception;
	}
}

new Foo;

Expected result:
----------------
I don't know what to expect. The manual says, that you can't catch an 
exeption thrown in an autoload function, but the crash only happens when 
the autoload function gets called the second time. Below code doesn't 
crash, but instead produces a Fatal error:
function __autoload($className) {
  throw new Exception;
}
new Foo;

Actual result:
--------------
Faulting application php.exe, version 5.3.0.0, faulting module 
php5ts.dll, version 5.3.0.0, fault address 0x0002358a.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-18 10:19 UTC] sjoerd@php.net
Could reproduce with php 5.3-head.
Backtrace: http://pastebin.com/f35c15146
 [2009-10-19 10:06 UTC] jani@php.net
Only crashes when the interface "Bar" is no defined.

 [2009-10-19 12:14 UTC] fqqdk at freemail dot hu
@jani:

sorry, i didn't make it clear. 
if Bar would have been defined, the autoloader wouldn't have to be 
called for the second time. 
but when it is called the second time, it is unstable, and i think it 
is the propagation of the exception that causes the crash.

The exception can be caught inside the autoloader function:

function __autoload($className) {
	if($className == 'Foo') {
		class Foo implements Bar {}
	} else {
		try {
			throw new Exception('message');
		} catch(Exception $ex) {}
	}
}

new Foo;

this code produces a fatal error:
Fatal error: Interface 'Bar' not found in bug.php on line 5
 [2009-11-01 21:26 UTC] svn@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&revision=290129
Log: - Fixed bug #49908 (throwing exception in __autoload crashes when interface is not defined)
 [2009-11-01 21:26 UTC] felipe@php.net
This bug has been fixed in SVN.

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.


 [2009-11-02 18:11 UTC] svn@php.net
Automatic comment from SVN on behalf of pajoye
Revision: http://svn.php.net/viewvc/?view=revision&revision=290152
Log: - Merge 290129, Fixed bug #49908 (throwing exception in __autoload crashes when interface is not defined)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 09:01:30 2024 UTC