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: -
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:
Status: Open Package: SPL related
PHP Version: 5.3.14 OS: N/A
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 10:01:24 2019 UTC