class - PHP Calling self on a non-static method -
why 'self'-call non-satic method in example working?
class a{ protected function anonstaticmethod(){ return __class__; } public function aecho(){ echo self::anonstaticmethod(); } }
thanks explanation.
in simple example $this , self interchangable. aware of different method resolving when dealing inheritance (i added static completeness):
class { protected function anonstaticmethod(){ return __class__; } public function selfecho(){ echo self::anonstaticmethod(); } public function staticecho(){ echo static::anonstaticmethod(); } public function thisecho(){ echo $this->anonstaticmethod(); } } class b extends { protected function anonstaticmethod(){ return __class__; } } $b = new b(); $b->selfecho(); // $b->staticecho(); // b $b->thisecho(); // b
Comments
Post a Comment