Connecting Tech Pros Worldwide Help | Site Map

What's the correct syntax for calling a static method in PHP5

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 02:29 AM
Chung Leong
Guest
 
Posts: n/a
Default What's the correct syntax for calling a static method in PHP5

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?



  #2  
Old July 17th, 2005, 02:29 AM
Agelmar
Guest
 
Posts: n/a
Default Re: What's the correct syntax for calling a static method in PHP5

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:[color=blue]
> 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?[/color]


  #3  
Old July 17th, 2005, 02:29 AM
Chung Leong
Guest
 
Posts: n/a
Default Re: What's the correct syntax for calling a static method in PHP5

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...[color=blue]
> Can't you just use Boo()? (That's how one would do it in C++, haven't[/color]
really[color=blue]
> looked into PHP5 that heavily yet.)
>
> Chung Leong wrote:[color=green]
> > 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?[/color]
>
>[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.