Edit report at https://bugs.php.net/bug.php?id=61442&edit=1

 ID:                 61442
 Updated by:         larue...@php.net
 Reported by:        yks-uno at yandex dot ru
 Summary:            SPL autoload issues Fatal Error if a handler throws
                     exception
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            SPL related
 Operating System:   Linux, FreeBSD
 PHP Version:        5.3.10
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

if you just want to check whether a class exists, use class_exists.

you test script is trying to call a method of a non-exists class,  fatal error 
is 
reasonable .


Previous Comments:
------------------------------------------------------------------------
[2012-09-19 07:15:33] yoorick at samovarchik dot info

If you try to use a class constant (e.g. Foo::BAR) of an unexisting class, 
autoloader will also fail to throw an exception and the script will die with 
the "class not found" fatal error.
(PHP 5.3.16)

------------------------------------------------------------------------
[2012-03-19 19:18:01] 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



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=61442&edit=1

Reply via email to