Re: context when calling non static method of class in a static way

From: Date: Sun, 22 May 2011 21:18:51 +0000
Subject: Re: context when calling non static method of class in a static way
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-313083@lists.php.net to get a copy of this message
class A { public function b() { echo get_class($this); } static function c() { echo get_class($this); } } class B { public function test(){ A::b(); A::c(); } } $b = new B; $b->test(); Generates: Strict Standards: Non-static method A::b() should not be called statically, assuming $this from incompatible context in /tmp/test.php on line 14 B Notice: Undefined variable: this in /tmp/test.php on line 8 A I would never use code generating warnings and notices like that. I'd look into late static bindings instead: http://php.net/manual/en/language.oop5.late-static-bindings.php Regards Peter -- <hype> WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15 </hype>

« previous php.general (#313083) next »