Re: Remove $this from incompatible context

From: Date: Sun, 15 Feb 2015 19:48:09 +0000
Subject: Re: Remove $this from incompatible context
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to internals+get-82745@lists.php.net to get a copy of this message
On 15/02/2015 19:32, Marc Bennewitz wrote:
Am 15.02.2015 um 19:09 schrieb Rowan Collins:
<snip> The static modifier for methods is part of the method signature and method body isn't. (That's way interfaces doesn't describe method bodies but signatures) The static modifier defines a method as static and therefore defines the method is callable using "::". More specifically, it defines that the method is *only* callable statically. There is currently no opposite keyword to say that a method can only be called non-statically, but the absence of a modifier has up until now meant that either call type is possible. An interface cannot currently forbid static calls, only the use of $this. Our choice is between keeping that ambiguity, and introducing a new rule that any method not marked static must never be called statically (with provisos for technically non-static parent:: etc). Regards,
The problem with the current behavior of "... the absence of a modifier has up until now meant that either call type is possible" is that the library author can't define a method as non static callable and the caller defines if $this can be used.
Agreed. Personally, I'm a great fan of symettry, so part of me would prefer to introduce a keyword for when you *can't* call a method statically, e.g. "instance function foo() { ... }". But I guess instance methods are, or at least "should" be, the majority, so it makes sense to reserve the un-annotated form for them. I worry about how many people will still miss the deprecation warning, but then I'm a broken record on the subject of PHP's warning system needing an overhaul. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#82745) next »