Re: Remove $this from incompatible context
| From: | Marc Bennewitz | Date: | Fri, 13 Feb 2015 04:45:19 +0000 |
| Subject: | Re: Remove $this from incompatible context | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-82578@lists.php.net to get a copy of this message | ||
Hi Stas,
Am 12.02.2015 um 22:31 schrieb Stanislav Malyshev:
Hi!Such code will break, not in the first place but later on! You propose that every instance method not using the variable $this internally will be magically a static method and can never ever be changed to use $this without an bc break.class A {IMHO, this should work. Maybe issue E_STRICT, but even then I'd think it's not really necessary, I can't see any purpose E_STRICT serves in this case - since $this is not used, no potential bug is averted, as the code works exactly as it was supposed to be working.// This is an *instance* method, but it doesn't actually use $this. // This kind of usage is very common in PHP 4 era code, where // "static" annotations weren't used function test() { echo "foo"; }} class B {function test2() { // This call would be forbidden because it assumes $this of classB, when// calling an instance method of class A. However A::test() doesnot actually// use $this! A::test(); }}
<snip>Marc