Re: [RFC] Forbid $this being null in instance methods
| From: | Bishop Bettini | Date: | Fri, 29 Apr 2016 17:42:58 +0000 |
| Subject: | Re: [RFC] Forbid $this being null in instance methods | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92955@lists.php.net to get a copy of this message | ||
On Fri, Apr 29, 2016 at 1:12 PM, Nikita Popov <nikita.ppv@gmail.com> wrote:
> Hi internals!
>
> I'd like to submit a small RFC for your consideration, which ensures
> something that really ought to be a given already: If you use $this in an
> instance method, you should actually get a $this (and not NULL).
>
> https://wiki.php.net/rfc/forbid_null_this_in_methods
>
> As this is targeting PHP 7.1, the RFC is careful to retain compatibility
> with certain legacy PHP 4 code patterns.
>
What is the performance cost of inspecting the method for $this, and is
that inspection impervious to tricks that shield $this?
Example:
A::method();
class A {
public function method() {
$foo = function () {
$this->something();
}
}
}
Does that throw an \Error? Would it throw an \Error if $foo() were called?