php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60182 Implicit call to spl_autoload_call() does not throw exceptions
Submitted: 2011-10-31 22:41 UTC Modified: 2013-08-06 08:30 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: pavel dot zubkou at gmail dot com Assigned: yohgaki (profile)
Status: Closed Package: SPL related
PHP Version: 5.3.8 OS: Debian GNU/Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pavel dot zubkou at gmail dot com
New email:
PHP Version: OS:

 

 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-07 12:09 UTC] francois dot dambrine at isen-lille dot fr
As I run the test with 5.4b1 the result is :

#0  autoload(A)
#1  spl_autoload_call(A) called at [/home/isen/essai.php:12]
Erreur de segmentation
 [2013-08-06 08:30 UTC] yohgaki@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: yohgaki
 [2013-08-06 08:30 UTC] yohgaki@php.net
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
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 20:01:31 2025 UTC