Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93492 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17348 invoked from network); 24 May 2016 19:21:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 May 2016 19:21:07 -0000 Authentication-Results: pb1.pair.com header.from=dev@mabe.berlin; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=dev@mabe.berlin; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mabe.berlin from 80.237.132.167 cause and error) X-PHP-List-Original-Sender: dev@mabe.berlin X-Host-Fingerprint: 80.237.132.167 wp160.webpack.hosteurope.de Received: from [80.237.132.167] ([80.237.132.167:51214] helo=wp160.webpack.hosteurope.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 14/00-17017-1A9A4475 for ; Tue, 24 May 2016 15:21:07 -0400 Received: from dslc-082-082-190-189.pools.arcor-ip.net ([82.82.190.189] helo=[192.168.178.46]); authenticated by wp160.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) id 1b5Ht0-0005XM-Q5; Tue, 24 May 2016 21:21:02 +0200 To: internals@lists.php.net References: Message-ID: <906d46a8-e0b3-9650-b8e1-be6ab669d545@mabe.berlin> Date: Tue, 24 May 2016 21:21:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-bounce-key: webpack.hosteurope.de;dev@mabe.berlin;1464117667;b3363068; Subject: Re: [PHP-DEV] [RFC] Fix inconsistent behavior of $this variable From: dev@mabe.berlin (Marc Bennewitz) On 05/24/2016 11:57 AM, Rowan Collins wrote: > On 24/05/2016 06:45, Jesse Schalken wrote: >> I'm curious, what is it about $this that makes it special in the first >> place? Can't it be a normal local variable that happens to already be >> assigned at the start of a method? > > There are a few things that take advantage of its specialness, e.g. > > - binding a closure to an object changes the meaning of $this in a way > very different from assigning it into scope with "use($this)" > - a method declared static can detect and throw errors on anything > referencing $this > - when calling parent::foo() from an instance method, the value of > $this needs to be set appropriately on the new method; being able to > reassign $this could lead to some odd behaviour there > > Python's approach is certainly valid, and leads to some different > useful properties, I'm sure, but it's a very different design, not > just a more relaxed attitude to assignment. As of $this is a very special variable where only the engine is (or should) be allowed to change. I would like to ask you if it wouldn't be better to NOT define $this as a special variable including a lot of code to make sure this variable doesn't get re-assigned but instead define this as a keyword like self where the syntax makes sure it can't be re-assigned and it's less special and simpler to learn for beginners. I know it would be a huge BC break but for me it sounds more "right" and could also be introduced in parallel to $this for a long long time but without a lot of overplayed code for $this. Thanks, Marc > > Regadrds,