NYCPHP Meetup

NYPHP.org

[nycphp-talk] self:: or $this ?

Jeremy Mcentire jmcentire at zootoo.com
Mon Nov 12 11:20:38 EST 2007


> Dan Cech wrote:
>> Morgan Craft wrote:
>>> Any reason why I should use $this->methodName()  over  
>>> self::methodName()
>>> Or is the self::methodName() reserved only for working within a  
>>> static
>>> method?
>>
>> The deciding factor is the nature of methodName()
>>
>> self::methodName() if methodName is static
>> $this->methodName() if methodName is not static
>
> One interesting twist, self::methodName is not inherited:
>

Of course, it is as expected.  $this-> refers to the instantiated  
object -- in the previous example that object was of subclass.   
Whereas self:: refers to the class in which it occurs -- which, for  
the this_self() method in parentclass, was parentclass.

Good point, though, Dan.  It certainly tripped me up before I thought  
about it.

Jeremy



More information about the talk mailing list