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 Christopher Fulton on 09/30/03 11:05

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 {
function drive() {
return $this->getClassName();
}
function getClassName() {
return "Car";
}
}

class Porshe {
function getClassName() {
return "Porshe";
}
}

$foo = new Porshe();
echo $foo->drive();


On Tue, 11 Jan 2005 17:08:27 +0100, Torsten Roehr <roehr@zilleon.com> wrote:
> Hi list,
>
> in PHP4 it was possible to get the name of the calling class with
> debug_bcktrace(). Unfortunately this behaviour has been changed in PHP5. I
> didn't find a solution in the archives.
>
> Is there *any* way to get the name of the calling class?:
>
> class Car {
> function drive() {
> // I need the name of the calling class here
> // in this case it should be 'Porsche'
> }
> }
>
> class Porsche extends Car {
> }
>
> Porsche::drive();
>
> Any help is greatly appreciated!
>
> Thanks and best regards,
>
> Torsten Roehr
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

 

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

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