You are here: Re: [PHP] Get name of extending class with static method call « PHP « IT news, forums, messages
Re: [PHP] Get name of extending class with static method call

Posted by Torsten Roehr on 10/03/22 11:05

> 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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация