Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92521 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91013 invoked from network); 20 Apr 2016 06:01:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2016 06:01:21 -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:32810] helo=mail-yw0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/81-14036-F2B17175 for ; Wed, 20 Apr 2016 02:01:19 -0400 Received: by mail-yw0-f176.google.com with SMTP id t10so42921004ywa.0 for ; Tue, 19 Apr 2016 23:01:19 -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=mJB0irMZ/WUlKZYuPmglixRIOrf1Oui675T7q8Y09Ng=; b=pdg2EzTnjpwWb26j7yaPIprkQyKYMtGOKG8jtpT+HQdkd0nOyerhQUOox/YB6w6mO5 n7RjCzFvQv6zNG3GSLC5mTLBvub3wjSC3IYAzZlxzPcib9qVIg1HimE790sPHSes2uUY WtNTzMtLGZXEI15k23HF6hVRWRkPYiaFFB/T6IrsdlCndbjYAHd4WkQf4mC+YdTDlS8a DtRveAomhD1MtUJW+ktgkm1mcFrRry/Ht7DjXZnPKW8dyBrCNxHH6FMTOJvTqi41Q7Cq OlA3RdcPqKcZl+/qeyfDf10rUJxEAzm41s9Pll6ed14GTUhz7HwwEBlQrGOIHYn5QUtW DKTw== 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=mJB0irMZ/WUlKZYuPmglixRIOrf1Oui675T7q8Y09Ng=; b=MSz6Wm4/7XNP2SR+kAdG57PATRxTAxKLZrC711TcOFxrdmnH40V0vh+I0yAwYPFmZR DB1RRCvI+Jja6BQ4pPJps1NoUnfV7dapjrSUkUAmHgSta5rZyvhsxeJxOAbG4ldzE2QR XCjYwW4r/MswPSdejRSSZe2MxPdwTHCazhloN9ounHBUWYcrdlO2FCu9WczOfLRbqeGi KF4zS98h6pKxRP6hKXNj6dgB/WZ/DYBAHgVQk2sjhlSybHQcUobSHliP8C86QV7/A88/ iNiuqbWzqNxJj54f0kxZ7dY9/xY8+705iPZ3ymWt6feMFoztgt/ztmvN0dF4+SCKwF6h uA9g== X-Gm-Message-State: AOPr4FVFxmg+3qaJDP5r6qZi/FDBOxs/9eWvT/uaSVWy5shDrrTuxvsewc7ZsLbuKTpLdm8XsERDBGfDa5xKEg== MIME-Version: 1.0 X-Received: by 10.129.44.139 with SMTP id s133mr4823315yws.182.1461132076388; Tue, 19 Apr 2016 23:01:16 -0700 (PDT) Received: by 10.129.39.9 with HTTP; Tue, 19 Apr 2016 23:01:16 -0700 (PDT) X-Originating-IP: [109.159.6.57] In-Reply-To: References: Date: Wed, 20 Apr 2016 07:01:16 +0100 Message-ID: To: Jesse Schalken Cc: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary=001a1141e82a62443f0530e4527d Subject: Re: [PHP-DEV] RFC: Anonymous Class Lexical Scope From: pthreads@pthreads.org (Joe Watkins) --001a1141e82a62443f0530e4527d Content-Type: text/plain; charset=UTF-8 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 >> > > --001a1141e82a62443f0530e4527d--