Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92522 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93581 invoked from network); 20 Apr 2016 06:36:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2016 06:36:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=pthreads@pthreads.org; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=pthreads@pthreads.org; sender-id=unknown Received-SPF: error (pb1.pair.com: domain pthreads.org from 209.85.161.176 cause and error) X-PHP-List-Original-Sender: pthreads@pthreads.org X-Host-Fingerprint: 209.85.161.176 mail-yw0-f176.google.com Received: from [209.85.161.176] ([209.85.161.176:35782] helo=mail-yw0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 69/E1-14036-E7327175 for ; Wed, 20 Apr 2016 02:36:47 -0400 Received: by mail-yw0-f176.google.com with SMTP id g133so38345572ywb.2 for ; Tue, 19 Apr 2016 23:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pthreads-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=Ph1ubI9dIt9uQltyOE12QVkDfOSzkq503C9/C0eFqzw=; b=ioMQCHXkEG6JkeUPJAYz5qow9G1PVExx4n+mEhZjB2f6ez9J5dV29oVRAqfA+xlDT6 RYxk6ht/sGO9XB8Qk9TJEJntIMP1+Rt4oWvmngEL+P6l1KriuZpjwkHe/Y/mlJEjkbbO Lr8qv+amCPUIcJSkkYt5B5utYJBzuLyAgA28ukMB+KrLutqEoldMTNcFJuVwErcyxOIW OjJAkGrCyC+FrUtAa7xYYg9eEmye2K0wVx8vtoq74gCCxP1Eih35w1ZNXVPzneg4MoUz MqpDvagqbowgFvgIsAfl+Mgnzd4aHcd52JPakwnFzLLkE65aA8N0GCmZ0fE2yag9+bL9 NoBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=Ph1ubI9dIt9uQltyOE12QVkDfOSzkq503C9/C0eFqzw=; b=ZKCf4kT0f9scStXl04tLU/xJq6KI6+378GIvgv9g26Iut2PaJXsaZZYO6pvgTrx89u Ixdhj0LREtWkZR5tRrpSt7ySAjqDoyhdCk5vbNrnxnyaY9NTqxbZsvJKodJPmvXVm0ma Jx5kAJy1bSQaTvoqvZgl3mI7dD8wVL2EvmHYQd3NLs0j9bfO2Nw7TkxMIRVAMGhHDiAz Oq304LHIRFtalQhyI/bTq5fo0VW7LtKvR3ihC8RkvZSygsNSCbwWxYe3mzUTS5SzZ34d M55ijB0PVsiKjFhLYRQOZlm/LlCTgTNzDQYdFWE4CkGDC28CbC5HYHHE4u7d1wFMOl51 HIUw== X-Gm-Message-State: AOPr4FXXUeN1J5BJ2hrr27SMAjnCX6W9tuciOnASPG8T6Ce08jbUiU0MtyZmBEDQhjCJW5VSbcPthTSHvvTa+w== MIME-Version: 1.0 X-Received: by 10.129.33.133 with SMTP id h127mr4808587ywh.169.1461134204067; Tue, 19 Apr 2016 23:36:44 -0700 (PDT) Received: by 10.129.39.9 with HTTP; Tue, 19 Apr 2016 23:36:43 -0700 (PDT) X-Originating-IP: [109.159.6.57] In-Reply-To: References: Date: Wed, 20 Apr 2016 07:36:43 +0100 Message-ID: To: Jesse Schalken Cc: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary=001a1142926234120c0530e4d1bb Subject: Re: [PHP-DEV] RFC: Anonymous Class Lexical Scope From: pthreads@pthreads.org (Joe Watkins) --001a1142926234120c0530e4d1bb Content-Type: text/plain; charset=UTF-8 Oh, I fixed it ... I think ... carry on ... Cheers Joe On Wed, Apr 20, 2016 at 7:01 AM, Joe Watkins wrote: > Can we just halt this conversation for a few days. > > That implementation is totally and utterly wrong, it's so obvious this > morning ... I'm almost embarrassed. > > I must say that of all the suggestions made so far for syntax, I still > prefer use(). > > While the idea to allow symbols and expressions is very cool, it will > create so much confusion that an anonymous class can do things like set > objects as member properties but other classes can't. > > The syntax also looks absolutely terrible when it comes to refs: > > class { > public $thing = &$this->thing; > } > > This is almost literally *backwards*. > > All of the solutions suggested so far also create rather a lot of > repetition for anything that isn't example code. > > Anyway, the implementation is broken, let's come back to this discussion > later on, please. > > Cheers > Joe > > On Wed, Apr 20, 2016 at 4:54 AM, Jesse Schalken > wrote: > >> 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 >>> >> >> > --001a1142926234120c0530e4d1bb--