Re: [RFC] Fix inconsistent behavior of $this variable
| From: | Jesse Schalken | Date: | Tue, 24 May 2016 08:41:37 +0000 |
| Subject: | Re: [RFC] Fix inconsistent behavior of $this variable | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-93478@lists.php.net to get a copy of this message | ||
On Tue, May 24, 2016 at 5:54 PM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote:
> Jesse,
>
> $this must be a object you're accessing.
>
Why? I consider it a kind of implied parameter. You can reassign self in
Python for example.
class MyClass:
def foo(self, p1, p2):
self = 7
print(self, p1, p2)
c = MyClass()
c.foo(8, 3); # 7 8 3
I can't think of anything else that allows it, though.
If you can change $this, you'll suddenly loose object.
>
That's what tends to happen when you assign a variable.
> PHP 4 treated $this as regular variable and caused lots of problems.
>
I'll have to take your word for it. I just thought the language would be
simpler with fewer "special" things that don't need to be special.
> Regards,
>
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net
>