trq Posted September 27, 2011 Share Posted September 27, 2011 Here is an oddity I just accidentally bumped into. #!/usr/bin/php <?php class foo { public function bar() { echo "this is bar"; } public function callBar() { $this->bar(); } } class someother { public function callFooBar() { echo foo::callBar(); } } $so = new someother; $so->callFooBar(); This means you can now do.... #!/usr/bin/php <?php class foo { public function bar() { echo "this is bar"; } public function callBar() { $this->bar(); } } class someother { public function callFooBar() { echo foo::callBar(); } public function bar() { echo "this is someother bar"; } } $so = new someother; $so->callFooBar(); Not sure it's useful, or just weird behaviour. Link to comment https://forums.phpfreaks.com/topic/247990-an-odity/ Share on other sites More sharing options...
SparK_BR Posted September 28, 2011 Share Posted September 28, 2011 is that because you used $this and called foo as static context and it found the closest instance context to get "$this" value? really interesting Link to comment https://forums.phpfreaks.com/topic/247990-an-odity/#findComment-1273675 Share on other sites More sharing options...
trq Posted September 28, 2011 Author Share Posted September 28, 2011 That is indeed what is happening. Link to comment https://forums.phpfreaks.com/topic/247990-an-odity/#findComment-1273749 Share on other sites More sharing options...
Philip Posted September 29, 2011 Share Posted September 29, 2011 Whoah, that is tricky. IMO that shouldn't happen, but what do I know On output this is what I see: Strict Standards: Non-static method foo::callBar() should not be called statically, assuming $this from incompatible context in [..]foo.php on line 17 this is someother bar Link to comment https://forums.phpfreaks.com/topic/247990-an-odity/#findComment-1273784 Share on other sites More sharing options...
SparK_BR Posted October 6, 2011 Share Posted October 6, 2011 Whoah, that is tricky. IMO that shouldn't happen, but what do I know On output this is what I see: Strict Standards: Non-static method foo::callBar() should not be called statically, assuming $this from incompatible context in [..]foo.php on line 17 this is someother bar Good, at least PHP tells you something is wrong Link to comment https://forums.phpfreaks.com/topic/247990-an-odity/#findComment-1276412 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.