This is a discussion on What's the correct syntax for calling a static method in PHP5 within the PHP Language forums, part of the PHP Programming Forums category; Say I have a class in PHP5 that looks like this: class Hello{ function Moo() { } static function Boo() { } static function ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Say I have a class in PHP5 that looks like this:
class Hello{ function Moo() { } static function Boo() { } static function Loo() { } } From within Moo(), how would I invoke Boo()? $this->Boo() seems to work, but doesn't feel right. And if I'm in Loo(), there's no $this. Is there a pseudo-classname akin to "parent" but refers to the current class that can be used, or do we have to type in the class name everytime we call a statis method? |
|
|||
|
Can't you just use Boo()? (That's how one would do it in C++, haven't really
looked into PHP5 that heavily yet.) Chung Leong wrote: > Say I have a class in PHP5 that looks like this: > > class Hello{ > > function Moo() { > } > > static function Boo() { > } > > static function Loo() { > } > } > > From within Moo(), how would I invoke Boo()? $this->Boo() seems to > work, but doesn't feel right. And if I'm in Loo(), there's no $this. > > Is there a pseudo-classname akin to "parent" but refers to the > current class that can be used, or do we have to type in the class > name everytime we call a statis method? |
|
|||
|
Ok, I found the keyword through a little bit of trial and error. It's
"self": class Hello { function Moo() { self::Boo(); } static function Boo() echo "Boo"; } static function Loo() { self::Boo(); } } Boo() alone would trigger an undefined function error. Uzytkownik "Agelmar" <ifetteNOSPAM@comcast.net> napisal w wiadomosci news:bubvt9$g87ss$1@ID-30799.news.uni-berlin.de... > Can't you just use Boo()? (That's how one would do it in C++, haven't really > looked into PHP5 that heavily yet.) > > Chung Leong wrote: > > Say I have a class in PHP5 that looks like this: > > > > class Hello{ > > > > function Moo() { > > } > > > > static function Boo() { > > } > > > > static function Loo() { > > } > > } > > > > From within Moo(), how would I invoke Boo()? $this->Boo() seems to > > work, but doesn't feel right. And if I'm in Loo(), there's no $this. > > > > Is there a pseudo-classname akin to "parent" but refers to the > > current class that can be used, or do we have to type in the class > > name everytime we call a statis method? > > |
|
|||
|
>From within Moo(), how would I invoke Boo()? $this->Boo() seems to work, but
>doesn't feel right. And if I'm in Loo(), there's no $this. function Moo() { Hello::Boo(); } or function Moo() { self::Boo(); } -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ Wil Moore III, MCP Site : www.quicksitedesign.com?em Application Developer Site : www.digitallysmooth.com?em ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ |