|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-10-31 22:41 UTC] pavel dot zubkou at gmail dot com
Description:
------------
Exceptions thrown from custom autoload function are not thrown outside the
spl_autoload_call() function when it is implicitly called on expressions like
'A::someMethod();' and '$b = A::CONSTANT;', i.e. when accessing static methods
and constants of the class.
Test script:
---------------
<?php
function autoload($class)
{
debug_print_backtrace();
throw new Exception('Test message');
}
spl_autoload_register('autoload');
try {
A::$someVariable;
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
try {
A::someMethod();
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
Expected result:
----------------
#0 autoload(A)
#1 spl_autoload_call(A) called at [/tmp/1.php:12]
Test message
#0 autoload(A)
#1 spl_autoload_call(A) called at [/tmp/1.php:18]
Test message
Actual result:
--------------
#0 autoload(A)
#1 spl_autoload_call(A) called at [/tmp/1.php:12]
Test message
#0 autoload(A)
#1 spl_autoload_call(A) called at [/tmp/1.php:18]
PHP Fatal error: Class 'A' not found in /tmp/1.php on line 18
PHP Stack trace:
PHP 1. {main}() /tmp/1.php:0
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 15 12:00:01 2025 UTC |
It seems fixed at least in 5.4 [yohgaki@dev PHP-5.4]$ ./php-bin -a Interactive shell php > echo 1290594600000 % 86400000; 378000 [yohgaki@dev PHP-5.4]$ ./php-bin <?php function autoload($class) { debug_print_backtrace(); throw new Exception('Test message'); } spl_autoload_register('autoload'); try { A::$someVariable; } catch (Exception $e) { echo $e->getMessage() . "\n"; } try { A::someMethod(); } catch (Exception $e) { echo $e->getMessage() . "\n"; } #0 autoload(A) #1 spl_autoload_call(A) called at [-:12] Test message #0 autoload(A) #1 spl_autoload_call(A) called at [-:18] Test message