Re: Get name of extending class with static method call
| From: | Daniel Schierbeck | Date: | Tue, 11 Jan 2005 20:46:18 +0000 |
| Subject: | Re: Get name of extending class with static method call | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-206109@lists.php.net to get a copy of this message | ||
Torsten Roehr wrote:
"Christopher Fulton" <christopher.fulton@gmail.com> wrote in message news:bbbb9b3e050111092074cae919@mail.gmail.com...I'm not sure if this will work, but hey, you could give it a try. class Car { public static $className = __CLASS__; public static function drive () {Not sure if this is the best way to do it or not, but you can do this and it should (untested code) work..... class Car {Of course this might work but it requires the definition of such a method in *every* class I have. Any more ideas? Thanks in advance! Torstenfunction drive() { return $this->getClassName(); } function getClassName() { return "Car"; }} class Porshe {function getClassName() { return "Porshe"; }} $foo = new Porshe(); echo $foo->drive();
return self::$className;} } class Porche extends Car { public static $className = __CLASS__; } Porche::drive(); // Should return "Porche"