Bug #65006 [Opn->Ver]: spl_autoload_register fails with multiple callables using self, same method

From: Date: Mon, 20 Jun 2016 14:32:49 +0000
Subject: Bug #65006 [Opn->Ver]: spl_autoload_register fails with multiple callables using self, same method
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201753@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65006&edit=1

 ID:                 65006
 Updated by:         cmb@php.net
 Reported by:        byoung2 at gmail dot com
 Summary:            spl_autoload_register fails with multiple callables
                     using self, same method
-Status:             Open
+Status:             Verified
 Type:               Bug
 Package:            SPL related
 Operating System:   Windows or Linux
 PHP Version:        5.4.16
 Block user comment: N
 Private report:     N

 New Comment:

Confirmed: <https://3v4l.org/aMkoi>. Obviously, hhvm gets
that
right.


Previous Comments:
------------------------------------------------------------------------
[2013-06-10 15:05:14] byoung2 at gmail dot com

Description:
------------
spl_autoload_register should properly resolve 'self' to the current execution scope, which
it does for the 'first' class, but it does not for the 'second' class.  Only the
first autoload is registered.  If I change the method name in the 'second' class to
'load2' for example, and register array('self','load2') using
spl_autoload_register, it works. It also works if I replace 'self' with __CLASS__, which I
have done as a workaround. Using 'static' instead of 'self' has the same bug,
but __CLASS__ won't work in this case if you want late static binding.   

Test script:
---------------
<?php 
first::init();
second::init();
print_r(spl_autoload_functions());
class first
{
	public static function init() {
		spl_autoload_register(array('self','load'));
	}	
	public static function load($class) {}
}

class second
{
	public static function init() {
		spl_autoload_register(array('self','load'));
	}	
	public static function load($class){}
}

Expected result:
----------------
Array
(
    [0] => Array
        (
            [0] => first
            [1] => load
        )

    [1] => Array
        (
            [0] => second
            [1] => load
        )

)


Actual result:
--------------
Array
(
    [0] => Array
        (
            [0] => first
            [1] => load
        )

)



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



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


Thread (4 messages)

« previous php.bugs (#201753) next »