get_called_class returns empty on spl_autoload*
| From: | Pablo Fischer | Date: | Sun, 26 Apr 2009 21:28:29 +0000 |
| Subject: | get_called_class returns empty on spl_autoload* | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-43780@lists.php.net to get a copy of this message | ||
Hello,
Was playing with get_called_class inside an autoload method that is
registered via spl_autoload_register and noticed:
- If I use get_called_class inside an autoload method I get an empty
value from it
- However the same doesn't happen if I'm not using a registered autoload method
Was wondering if this is a bug, a feature or something I'm just missing :-)
The code I'm using is:
class Loader {
public static function autoload($className)
{
var_dump('Calling ' . get_called_class() . ' for ' . $className);
}
public static function getCalledClass()
{
var_dump('Current class is: ' . get_called_class());
}
}
spl_autoload_register(array('Loader', 'autoload'));
Loader::getCalledClass();
$foo = new Foo;
And I get:
string(24) "Current class is: Loader"
string(16) "Calling for Foo"
Fatal error: Class 'Foo' not found in
/Users/pablo/Projects/reptilia/test.php on line 17
Thanks!
--
Pablo Fischer (pablo [arroba/at] pablo.com.mx)