Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92517 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80598 invoked from network); 20 Apr 2016 03:54:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2016 03:54:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=jesseschalken@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jesseschalken@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.178 as permitted sender) X-PHP-List-Original-Sender: jesseschalken@gmail.com X-Host-Fingerprint: 209.85.223.178 mail-io0-f178.google.com Received: from [209.85.223.178] ([209.85.223.178:35296] helo=mail-io0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9B/00-14036-38DF6175 for ; Tue, 19 Apr 2016 23:54:44 -0400 Received: by mail-io0-f178.google.com with SMTP id g185so40206920ioa.2 for ; Tue, 19 Apr 2016 20:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc; bh=BaTTaN/CpYkpGdDjrkGO8DYkI+yCMEOXLr8VNowGCr0=; b=juprFaxUrT7OICKkJ3rmAGI8F7ve8yV6JsayZA7GRDrBa6eSl1Jec89ZJTiwoh/qW6 aC+C/zURCUjF3T//d8/tOJsJmGVoFiS5V6bEDEUlA6LN2r0D6cigdzHOnRqRf0KxRumA 5gEmkACBa5c44TAn+QQvpCme+9eJJx2yX55pkrq21mc1l0ckGqfd1yUwILnyULExPCpc Pb4ruBGWEArlNaEHRhbnk4z09Ru5sFumchvcGcvX+OpmaAhM9Rof6DO3ui3ij9A40Zfo InXUHgw8KDY4gVBFAMakYVMERAlg2s3j94IrPrBtdTayP1e5dBDMuE+1YlHbvGvbvdiC w/Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc; bh=BaTTaN/CpYkpGdDjrkGO8DYkI+yCMEOXLr8VNowGCr0=; b=SZ3bTbAtoC9wmsQLMgIHl7QunOlh8qXFbiAb2LIJDDSzk5jGVmOfxkGXNvXs++AD5Q CpQ1Q52+I7UuGleQrvkLV3qDbVizdfDmGyYdgoeViTxBScdIPvBZ9amLEWgFf6OL22MH /9wGOxvy/qLczixoxpBgTCNQfFZsI4wuKhcMYUuWGEvWgXfWZ2qEtFykE6pvapU74o6n InxU+PGVlOj6G8CfIoz8RCsvYMvnnnDyIfvq4EV+fI4Wxt+ByvCNANv2GKnm9GVXL0Is cAVEzOLG9um+TmtmmU1svvlYNiw+7AbJkMryG31nI1Ymi5DBLXBYR8KAXJocCyJG0WrO VKnQ== X-Gm-Message-State: AOPr4FVYTgPUzwQW+kI33V3NPeAIQYXrPIMcyfi25bGG6xEpzc/dURljDCk0Ry2gVwWRwoU8JixQrCSYAqnNBw== MIME-Version: 1.0 X-Received: by 10.107.137.101 with SMTP id l98mr7485338iod.31.1461124481598; Tue, 19 Apr 2016 20:54:41 -0700 (PDT) Sender: jesseschalken@gmail.com Received: by 10.79.139.133 with HTTP; Tue, 19 Apr 2016 20:54:41 -0700 (PDT) In-Reply-To: References: Date: Wed, 20 Apr 2016 13:54:41 +1000 X-Google-Sender-Auth: SUeW-FQCmhjQKKrgEqJ_KEnkasI Message-ID: To: Nikita Popov Cc: Joe Watkins , PHP internals Content-Type: multipart/alternative; boundary=001a113ed540b2d1870530e28dd6 Subject: Re: [PHP-DEV] RFC: Anonymous Class Lexical Scope From: me@jesseschalken.com (Jesse Schalken) --001a113ed540b2d1870530e28dd6 Content-Type: text/plain; charset=UTF-8 I'm not sure it matters, but there is some precedent for this in JavaScript/ES6: function foo(bar) { return new class { myBar = bar; getBar() { return this.myBar; } }(); } console.log(foo('hello').getBar()); // "hello" (You can actually reference outer symbols anywhere in the definition of a JS class, so I could have used "bar" directly in "getBar" without going through a property.) On Wed, Apr 20, 2016 at 12:18 AM, 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. > > Thanks, > Nikita > --001a113ed540b2d1870530e28dd6--