Bug #62408 [NEW]: spl_autoload_register() doesn't always register an auto loader

From: Date: Mon, 25 Jun 2012 13:45:33 +0000
Subject: Bug #62408 [NEW]: spl_autoload_register() doesn't always register an auto loader
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-171512@lists.php.net to get a copy of this message
From:             datibbaw@php.net
Operating system: N/A
PHP version:      5.3.14
Package:          SPL related
Bug Type:         Bug
Bug description:spl_autoload_register() doesn't always register an auto loader

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 bug report at https://bugs.php.net/bug.php?id=62408&edit=1
-- 
Try a snapshot (PHP 5.4):            https://bugs.php.net/fix.php?id=62408&r=trysnapshot54
Try a snapshot (PHP 5.3):            https://bugs.php.net/fix.php?id=62408&r=trysnapshot53
Try a snapshot (trunk):              https://bugs.php.net/fix.php?id=62408&r=trysnapshottrunk
Fixed in SVN:                        https://bugs.php.net/fix.php?id=62408&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62408&r=needdocs
Fixed in release:                    https://bugs.php.net/fix.php?id=62408&r=alreadyfixed
Need backtrace:                      https://bugs.php.net/fix.php?id=62408&r=needtrace
Need Reproduce Script:               https://bugs.php.net/fix.php?id=62408&r=needscript
Try newer version:                   https://bugs.php.net/fix.php?id=62408&r=oldversion
Not developer issue:                 https://bugs.php.net/fix.php?id=62408&r=support
Expected behavior:                   https://bugs.php.net/fix.php?id=62408&r=notwrong
Not enough info:                     https://bugs.php.net/fix.php?id=62408&r=notenoughinfo
Submitted twice:                     https://bugs.php.net/fix.php?id=62408&r=submittedtwice
register_globals:                    https://bugs.php.net/fix.php?id=62408&r=globals
PHP 4 support discontinued:          https://bugs.php.net/fix.php?id=62408&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=62408&r=dst
IIS Stability:                       https://bugs.php.net/fix.php?id=62408&r=isapi
Install GNU Sed:                     https://bugs.php.net/fix.php?id=62408&r=gnused
Floating point limitations:          https://bugs.php.net/fix.php?id=62408&r=float
No Zend Extensions:                  https://bugs.php.net/fix.php?id=62408&r=nozend
MySQL Configuration Error:           https://bugs.php.net/fix.php?id=62408&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#171512) next »