Bug #62408 [Opn->Csd]: spl_autoload_register() doesn't always register an auto loader

From: Date: Tue, 09 Jun 2020 16:14:43 +0000
Subject: Bug #62408 [Opn->Csd]: spl_autoload_register() doesn't always register an auto loader
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227381@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62408&edit=1

 ID:                 62408
 Updated by:         nikic@php.net
 Reported by:        datibbaw@php.net
 Summary:            spl_autoload_register() doesn't always register an
                     auto loader
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            SPL related
 Operating System:   N/A
 PHP Version:        5.3.14
-Assigned To:        
+Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

This seems to have been fixed in the meantime. (It works at least on 7.3, but probably much earlier
as well.)


Previous Comments:
------------------------------------------------------------------------
[2012-06-25 13:45:33] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=62408&edit=1


Thread (2 messages)

« previous php.bugs (#227381) next »