php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40091 spl_autoload_register with 2 instances of the same class
Submitted: 2007-01-10 15:20 UTC Modified: 2007-01-10 18:14 UTC
From: dweller at devonweller dot com Assigned:
Status: Closed Package: SPL related
PHP Version: 5.2.0 OS: Mac OS X
Private report: No CVE-ID: None
 [2007-01-10 15:20 UTC] dweller at devonweller dot com
Description:
------------
When using spl_autoload_register with two instances of the same class name, the autoload stack only stores one function callback instead of two.


Reproduce code:
---------------
class MyAutoloader {
	function __construct($directory_to_use) {}
	function autoload($class_name) {
		// code to autoload based on directory
	}
}

$autloader1 = new MyAutoloader('dir1');
spl_autoload_register(array($autloader1, 'autoload'));

$autloader2 = new MyAutoloader('dir2');
spl_autoload_register(array($autloader2, 'autoload'));

print_r(spl_autoload_functions());


Expected result:
----------------
Array
(
    [0] => Array
        (
            [0] => MyAutoloader
            [1] => autoload
        )

    [1] => Array
        (
            [0] => MyAutoloader
            [1] => autoload
        )

)


Actual result:
--------------
Array
(
    [0] => Array
        (
            [0] => MyAutoloader
            [1] => autoload
        )

)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-10 18:14 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC