php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62408 spl_autoload_register() doesn't always register an auto loader
Submitted: 2012-06-25 13:45 UTC Modified: 2020-06-09 16:14 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: datibbaw@php.net Assigned: nikic (profile)
Status: Closed Package: SPL related
PHP Version: 5.3.14 OS: N/A
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: datibbaw@php.net
New email:
PHP Version: OS:

 

 [2012-06-25 13:45 UTC] datibbaw@php.net
Description:
------------
When spl_autoload_register() is called from within another auto load operation, 
spl_autoload_functions() will list the newly registered loader until PHP is done 
executing the newly included file, after which the loader is removed from the 
loader functions.

Test script:
---------------
<?php

//generate auto loaded file first
$base = ucfirst(basename(__FILE__, '.php'));

$s = <<<EOM
<?php

$base::setup();

class $base
{
        public static function setup()
        {
                spl_autoload_register(array(__CLASS__, 'load'));
                print_r(spl_autoload_functions());
        }

        public static function load($class)
        {
                print_r(func_get_args());
        }
}
EOM;

file_put_contents(pathinfo(__FILE__, PATHINFO_FILENAME) . '.test.php', $s);

spl_autoload_extensions('.test.php');
spl_autoload_register();

new $base;
echo "after first autoload\n";
print_r(spl_autoload_functions());
echo "---\n";
new NonExistingClass;

Expected result:
----------------
after spl_autoload_register()
Array
(
    [0] => spl_autoload
    [1] => Array
        (
            [0] => Loader
            [1] => load
        )

)
after first autoload
Array
(
    [0] => spl_autoload
    [1] => Array
        (
            [0] => Loader
            [1] => load
        )

)
---
Array
(
    [0] => NonExistingClass
)

Fatal error: Class 'NonExistingClass' not found in loader.php on line 35

Actual result:
--------------
after spl_autoload_register()
Array
(
    [0] => spl_autoload
    [1] => Array
        (
            [0] => Loader
            [1] => load
        )

)
after first autoload
Array
(
    [0] => spl_autoload
)
---

Fatal error: spl_autoload(): Class NonExistingClass could not be loaded in 
loader.php on line 35

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-09 16:14 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-06-09 16:14 UTC] nikic@php.net
This seems to have been fixed in the meantime. (It works at least on 7.3, but probably much earlier as well.)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 13:01:33 2025 UTC