ravinggenius Posted August 1, 2008 Share Posted August 1, 2008 <?php class Model { private static $type = 'Model'; public static function test1() { $c = __CLASS__; echo "found a {$c} object\n"; } public static function test2() { $c = self::$type; echo "found a {$c} object\n"; } } class User extends Model { private static $type = 'User'; } Model::test1(); Model::test2(); echo "\n"; User::test1(); User::test2(); ?> This results in the following: found a Model object found a Model object found a Model object found a Model object As you can see in the example above, when I am in the User class, I cannot get the correct class name. Does anybody know of a way to find the name of the class when I am in an extended static method? That is, calling User::test1(); or User::test2(); should result in 'found a User object'. Is this even possible? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted August 1, 2008 Share Posted August 1, 2008 It's not possible. You'll have to use late static binding which is only in 5.3 and 6.0. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.