Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92463 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69680 invoked from network); 19 Apr 2016 14:22:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Apr 2016 14:22:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=ivan.enderlin@hoa-project.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=ivan.enderlin@hoa-project.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain hoa-project.net from 217.70.178.86 cause and error) X-PHP-List-Original-Sender: ivan.enderlin@hoa-project.net X-Host-Fingerprint: 217.70.178.86 slow1-d.mail.gandi.net Received: from [217.70.178.86] ([217.70.178.86:50557] helo=slow1-d.mail.gandi.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 66/94-43496-53F36175 for ; Tue, 19 Apr 2016 10:22:46 -0400 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by slow1-d.mail.gandi.net (Postfix) with ESMTP id C227547A8BC for ; Tue, 19 Apr 2016 16:22:42 +0200 (CEST) X-Originating-IP: 46.14.238.241 Received: from [10.0.1.128] (241.238.14.46.static.wline.lns.sme.cust.swisscom.ch [46.14.238.241]) (Authenticated sender: ivan.enderlin@hoa-project.net) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id AE51BA80CF for ; Tue, 19 Apr 2016 16:22:42 +0200 (CEST) To: internals@lists.php.net References: Message-ID: <57163F32.5010905@hoa-project.net> Date: Tue, 19 Apr 2016 16:22:42 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC: Anonymous Class Lexical Scope From: ivan.enderlin@hoa-project.net (Ivan Enderlin) On 19/04/16 16:18, Nikita Popov wrote: > On Tue, Apr 19, 2016 at 3:31 PM, Joe Watkins wrote: > >> Morning Internals, >> >> Please review the following RFC: >> >> https://wiki.php.net/rfc/lexical-anon >> >> A look at the patch from those of you that do that would be good :) >> > Hey Joe, > > The syntax and semantics proposed in this RFC don't sit quite well with me. > Especially the fact that a use($foo) on the class is then used as > $this->foo in methods is non-intuitive to me, as it differs from how the > same syntax behaves on closures. I'd like to suggest an alternative syntax: > > $foo = 42; > return new class { > private $bar = $foo; > public function getBar() { return $this->bar; } > } > > That is, allow properties inside the anonymous class to be initialized > based on values from the surrounding scope. This is more explicit (clearly > shows that a property is being created), it allows explicit control over > the visibility and, depending on implementation, might be more flexible > with regards to the values it accepts. It probably doesn't make sense to > restrict this to specific expressions, so all of > > return new class { > private $a = $var; > private $b = $obj->prop; > private $d = $obj->prop ?? 'default'; > // ... > } > > could be fine. I could not express better than you, so big +1 for your proposal so far.