Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92462 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67898 invoked from network); 19 Apr 2016 14:18:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Apr 2016 14:18:53 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.169 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.161.169 mail-yw0-f169.google.com Received: from [209.85.161.169] ([209.85.161.169:36707] helo=mail-yw0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2F/34-43496-A4E36175 for ; Tue, 19 Apr 2016 10:18:50 -0400 Received: by mail-yw0-f169.google.com with SMTP id o66so18455323ywc.3 for ; Tue, 19 Apr 2016 07:18:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=1c3xAOjnc5+8XHot0YcjR/aItd2tKI9YJaLxgETB7tQ=; b=jsiUZWSf2RYxEfwM3X1AdJ0cI5PRT8b/Q8HeE65kkjirnSDGU2lHbwowd6YyDr3+eQ hQ3hVA1Osg0vLGmQCjWTrYB1Mi9sBvN7PyUJBCT21X4IFngXmjubrUxnrUPzaaTnjeNY qRT2OLIeWUWAt6c8KgYQC+F4ucfd4zvEddbjmDv4DQqmYhWc/GC5hB27KZjvdZPHhY/j kMjs7X/IfwBkINMXdxoBDDXIX1Vq5SJuCDsDujh1SbVWBcHKO3l3j6iV3aysg0B1WqHR 2kprooYCt0Hd24xAW9U7Cd4n3X7hp5D+E4wMJ8RiekmVHD2ru0BxxJnhqpd5hGAZ6oWP KV5w== 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=1c3xAOjnc5+8XHot0YcjR/aItd2tKI9YJaLxgETB7tQ=; b=W65882/HKOu5aNDamIq5AZqRxgMGlbCqVbQqAERZkwuWZq31t2zRfHEcRknJwxI9i4 jtCPKZdZByC99Xin8qR9+psHyReQCjE13MHkC3lLaq7hwjpaiCJb/hRAfzVWUXpyy92e Rr5zEnW6q+QXbzHXmxbBkyul0qZTT5u614WZY3udglK13XuDIScWOG2Se4vTSCZ354Hf FnEmgkJyqguZiaCvH+2wKxkDKbCEWIz4E/KLvm2S3TQIfOwNMiq158gYXvdY6CpIaEhw Q9acs11Nn8wTekvl9E6IAsqog2hVcCmxkyGwBwyslwVjo6gSIhAn6iLXipstYgzWa3Km X/jg== X-Gm-Message-State: AOPr4FXg0DJoMLHaGYZAxV+ExoFBM3BW63S80He74bxI+Ew/pE65g4+PKW9CJC9BTy1EfgHpDo/gKxMsUC0e2g== MIME-Version: 1.0 X-Received: by 10.37.114.3 with SMTP id n3mr1767643ybc.158.1461075527271; Tue, 19 Apr 2016 07:18:47 -0700 (PDT) Received: by 10.13.239.3 with HTTP; Tue, 19 Apr 2016 07:18:47 -0700 (PDT) In-Reply-To: References: Date: Tue, 19 Apr 2016 16:18:47 +0200 Message-ID: To: Joe Watkins Cc: PHP internals Content-Type: multipart/alternative; boundary=001a114891c6cb09e80530d72726 Subject: Re: [PHP-DEV] RFC: Anonymous Class Lexical Scope From: nikita.ppv@gmail.com (Nikita Popov) --001a114891c6cb09e80530d72726 Content-Type: text/plain; charset=UTF-8 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 --001a114891c6cb09e80530d72726--