|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60816 spl_autoload_register fails with __call magic
Submitted: 2012-01-20 06:22 UTC Modified: 2017-12-06 22:53 UTC
From: dan dot lugg at gmail dot com Assigned: nikic (profile)
Status: Closed Package: SPL related
PHP Version: 5.3.9 OS: Windows 7x64
Private report: No CVE-ID: None
 [2012-01-20 06:22 UTC] dan dot lugg at gmail dot com
When registering a callback object/method pair to spl_autoload_register(), if 
method is not defined, though the object class has defined __call() magic, the 
method will not be called during an autoload attempt.

In a larger project, I found that the PHP executable was crashing out 
appending no output to the logs, and offering minimal information. When I 
what I suspected to be the problem, it was in fact the 
spl_autoload_register()/__call() combination. In isolation, it did not crash out 
spectacularly as in my project, however it still failed.

While I marked this 5.3.9, these failures have been observed on 5.3.8, 5.3.9, 

While this is a bit of an edge case, I doubt that this is expected or acceptable 
behaviour, and have not been able to find mention of this elsewhere.

Test script:

    class Loader
        public function __call($name, $arguments)
    spl_autoload_register(array(new Loader(), 'load_class'));
    $foo = new Bar();

Expected result:
    array(2) {
      string(10) "load_class"
      array(1) {
        string(3) "Bar"
    Fatal error: Class 'Bar' not found in - on line 12

Actual result:
    Fatal error: Class 'Bar' not found in - on line 12

As you can see, while this test script made no attempt to actually load the class, 
it should at least be dumping the array before failing, as in the expected output.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-20 06:57 UTC]
This works on viper-7:
 [2012-01-20 12:53 UTC] dan dot lugg at gmail dot com
Fellow programmers online have confirmed this may be a non-issue, however all 
cases where the problem did not crop up were on *nix flavours; perhaps it is an OS 
specific/related issue.
 [2017-12-06 22:53 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2017-12-06 22:53 UTC]
Here's a working reproducer:

This is a duplicate of bug #73896, which has been fixed with in 7.0.16, 7.1.2.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Sep 30 21:01:23 2020 UTC