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

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-17-2004
Chung Leong
 
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?


Reply With Quote
  #2 (permalink)  
Old 01-17-2004
Agelmar
 
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:
> 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?



Reply With Quote
  #3 (permalink)  
Old 01-18-2004
Chung Leong
 
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...
> 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?

>
>



Reply With Quote
  #4 (permalink)  
Old 01-18-2004
laidbak
 
Posts: n/a
Default Re: What's the correct syntax for calling a static method in PHP5

>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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:14 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0