On Thu, Feb 12, 2015 at 10:31 PM, Stanislav Malyshev <smalys...@gmail.com> wrote:
> Hi! > > > class A { > > // 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 class > > B, when > > // calling an instance method of class A. However A::test() does > > not actually > > // use $this! > > A::test(); > > } > > } > > 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 case, where an incompatible $this will be assumed, but never > actually > > used, seems to be very common in PEAR, for example. Another weirdness of > > forbidding this call is that the following very similar code would work > and > > only throw an E_STRICT notice: > > > > // NOT in a class > > function test3() { > > A::test(); // E_STRICT > > } > > Yes, this should work too, and I'm again not sure how useful is E_STRICT > even here. > > > The compromise I'd like to implement instead is to only throw a fatal > error > > if $this is actually used in the called method and otherwise throw a > > deprecation warning. Calls from instance methods, static methods and > > I would go even further and if $this is not there just let it work. > Assuming $this from different context is broken, but if $this not > involved, what's the harm? The call to different context should just > drop $this and treat it as if it were a call from global scope. > It was always an E_STRICT error to call a non-static method statically (as usual, not counting scoped calls) and since PHP 5.6 it was E_DEPRECATED in the most common case. I don't see why we would suddenly want to go back on this and make it work without any warnings. Nikita