exception threw in __autoload can not be catched
| Bug #61442 | exception threw in __autoload can not be catched | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2012-03-19 19:18 UTC | Modified: | 2012-09-19 15:40 UTC |
|
||||||||||
| From: | yks-uno at yandex dot ru | Assigned: | laruence (profile) | |||||||||||
| Status: | Closed | Package: | Scripting Engine problem | |||||||||||
| PHP Version: | 5.3.10 | OS: | Linux, FreeBSD | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[2012-03-19 19:18 UTC] yks-uno at yandex dot ru
Description:
------------
If a handler is registered for autoloading (whether via spl_autoload_register() or __autoload()) and it throws an exception when a class is not found, the exception can not be caught as usual if a method of the target class is statically called. Instead, a Fatal Error: Class not found is issued (which is quite what the autoloader is meant to avoid!)
Yet, when, e.g. trying to access a static field of that class, the exceptions get caught correctly.
Tested on several PHP versions (5.3.3 - 5.3.10) on Linux and FreeBSD.
Test script:
---------------
<?
function x($class)
{
print "xxx\n"; // gets printed
throw new Exception("Class '{$class}' not found");
}
spl_autoload_register('x');
try {
$a = A::z(); // FATAL ERROR: class 'A' not found
// NOTE:
// $a = A::$z; - will be correctly caught
} catch (Exception $ex) {
print "{$ex}\n"; // never gets executed
}
Expected result:
----------------
xxx
exception 'Exception' with message 'Class 'A' not found' in <FILE>:5
---
this is what gets output in case the exception is caught
Actual result:
--------------
xxx
Fatal error: Class 'A' not found in <FILE> on line 10
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2012-09-19 07:15 UTC] yoorick at samovarchik dot info
[2012-09-19 07:44 UTC] laruence@php.net
[2012-09-19 08:43 UTC] yks-uno at yandex dot ru
[2012-09-19 08:54 UTC] yks-uno at yandex dot ru
[2012-09-19 10:03 UTC] laruence@php.net
[2012-09-19 10:09 UTC] laruence@php.net
[2012-09-19 10:33 UTC] laruence@php.net
hmm, seems I thought wrongly, try { new AAAA(); } catch () { } can be catched in 5.3 but try { AAA:xxx(); } can not be catched in 5.3, but can be catched in 5.4.[2012-09-19 10:37 UTC] yks-uno at yandex dot ru
[2012-09-19 11:28 UTC] laruence@php.net
-Summary: SPL autoload issues Fatal Error if a handler throws exception +Summary: exception threw in __autoload can not be catched
[2012-09-19 11:41 UTC] laruence@php.net
-: yks-uno at yandex dot ru +: laruence@php.net -Status: Re-Opened +Status: Closed
[2012-09-19 11:42 UTC] laruence@php.net
-Package: SPL related +Package: Scripting Engine problem -Assigned To: +Assigned To: laruence
[2012-09-19 14:36 UTC] nikic@php.net
[2012-09-19 16:04 UTC] nikic@php.net