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

Posted by Jason Barnett on 10/07/46 11:05

Christopher Fulton wrote:
> This should work for you then....(maybe...i don't have php5 on my
> system, so it may not, but i think it would.
> http://us4.php.net/manual/en/function.get-class.php
>
> class Car {
> function drive() {
> return get_class($this);
> }
> }
>
> class Porshe {
> }
>
> $foo = new Porshe();
> echo $foo->drive();
>

Chris, I was thinking of this as well. Except that the method drive is
actually a static method so the class definition for Car is (I'm
assuming) more like this:

<?php

class Car {
static function drive() {
/** I am a static function, so $this should not exist! */
/** However, class constants and static variables are available */
}
}

class Porsche extends Car { }
Porsche::drive();

?>

Torsten, I also found the following link to be helpful. Check out the
user notes from michael at digitalgnosis dot removethis dot com (he did
something similar to what I have already suggested, i.e. call_user_func)

http://www.php.net/manual/en/language.oop5.static.php



--
Teach a person to fish...

Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
PHP Manual: http://www.php.net/manual/en/index.php
php-general archives: http://marc.theaimsgroup.com/?l=php-general&w=2

 

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

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