Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69357 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55278 invoked from network); 26 Sep 2013 19:08:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Sep 2013 19:08:14 -0000 Authentication-Results: pb1.pair.com smtp.mail=iam.asm89@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=iam.asm89@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.179 as permitted sender) X-PHP-List-Original-Sender: iam.asm89@gmail.com X-Host-Fingerprint: 209.85.220.179 mail-vc0-f179.google.com Received: from [209.85.220.179] ([209.85.220.179:64109] helo=mail-vc0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CD/73-37010-C1684425 for ; Thu, 26 Sep 2013 15:08:13 -0400 Received: by mail-vc0-f179.google.com with SMTP id ht10so1169692vcb.38 for ; Thu, 26 Sep 2013 12:08:09 -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 :content-type; bh=YjkaJ4p6Lk0LG13ZH8zEPRYkAc3vjzrHbx1qBcIS+kA=; b=pji2pDCZZu/uqxdPK5BFX/qWYw80zCVgK6YRRysZLejYzJnVTAO+3zRc2+TCszIny4 4jyxuXtU9pSCQWRy3D1hnYnYKAdnpwI7RRC4mmjJ71HSLeLNz8PGHI2qYuEblLHVEoL6 OoyapLaUDQpBaDMMtMmq8GpsOMpVC5m4U29/Z+o25UV5MIGhd8T4rpBOx0AkIu+4PIOp 79UbWsPfwOnTfeF9ar9jye/mOyB2mGzA8nceZXFuBT2eEjSeugxc+hH08KgDHaIGOmEi 0VP6YjalIb/9Q5q9//ksX91DD/MjOoPI+v/O6jNCSWOBLYbCw3R+qW+QEYX845DUzxyN FnoA== MIME-Version: 1.0 X-Received: by 10.58.181.230 with SMTP id dz6mr13103vec.35.1380222489300; Thu, 26 Sep 2013 12:08:09 -0700 (PDT) Received: by 10.52.182.6 with HTTP; Thu, 26 Sep 2013 12:08:09 -0700 (PDT) In-Reply-To: <524459D5.8050604@php.net> References: <5243F19F.3060307@php.net> <524459D5.8050604@php.net> Date: Thu, 26 Sep 2013 21:08:09 +0200 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] RFC: Anonymous Classes From: iam.asm89@gmail.com (Alexander M) On Thu, Sep 26, 2013 at 5:59 PM, Joe Watkins wrote: > Ok, I included just about all the information on use cases that is obvious > or has been discussed, so I think we got use cases covered now, right ?? > > See a good one yet ?? > > > Cheers > Joe Wondering about scoping. Yes, anonymous classes can have their own constructor, but if we're adding syntactic sugar why not make it possible to use from the scope they're created in? See this example adapted from a Stack Overflow question about how it works in Java [1]: (not sure how you the "use" syntax should look like) public function doStuff($userId) { $this->doOtherStuff($userId, new class implements SomeInterface { public function onSuccess() { echo $userId; } }); } vs public function doStuff($userId) { $this->doOtherStuff($userId, new class implements SomeInterface { private $userId; public function __construct($userId) { $this->userId = $userId; } public function onSuccess() { echo $this->userId; } }); } [1] http://stackoverflow.com/questions/3251018/java-anonymous-inner-class-using-a-local-variable Cheers, Alexander