Re: Get name of extending class with static method call

From: Date: Wed, 12 Jan 2005 09:17:02 +0000
Subject: Re: Get name of extending class with static method call
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-206152@lists.php.net to get a copy of this message
> 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 () > { > return self::$className; > } > } > > class Porsche extends Car > { > public static $className = __CLASS__; > } > > Porche::drive(); // Should return "Porche" Hi Daniel, thanks for the idea but it causes an error: Fatal error: Cannot redeclare property static public Car::$className in class Porsche If I ommit the definition of $className in Car I get this error: Fatal error: Access to undeclared static property: Car::$className If I ommit the definition of $className in Porsche the return value is 'Car' not 'Porsche'. Arrrgh! Will keep on trying. Best regards, Torsten

« previous php.general (#206152) next »