|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 11:00:02 2025 UTC |
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.