Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69324 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32823 invoked from network); 24 Sep 2013 19:01:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Sep 2013 19:01:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=pierre@pcservice.co.za; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pierre@pcservice.co.za; sender-id=pass Received-SPF: pass (pb1.pair.com: domain pcservice.co.za designates 67.18.125.13 as permitted sender) X-PHP-List-Original-Sender: pierre@pcservice.co.za X-Host-Fingerprint: 67.18.125.13 gateway06.websitewelcome.com Linux 2.6 Received: from [67.18.125.13] ([67.18.125.13:35940] helo=gateway06.websitewelcome.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FB/00-32366-791E1425 for ; Tue, 24 Sep 2013 15:01:44 -0400 Received: by gateway06.websitewelcome.com (Postfix, from userid 5007) id 64A376EC73D3D; Tue, 24 Sep 2013 14:01:40 -0500 (CDT) Received: from vinacomin.websitewelcome.com (vinacomin.websitewelcome.com [50.97.101.199]) by gateway06.websitewelcome.com (Postfix) with ESMTP id 4F2036EC73CE8 for ; Tue, 24 Sep 2013 14:01:40 -0500 (CDT) Received: from [209.85.216.46] (port=52824 helo=mail-qa0-f46.google.com) by vinacomin.websitewelcome.com with esmtpsa (TLSv1:RC4-SHA:128) (Exim 4.80) (envelope-from ) id 1VOXrg-0006fM-5z for internals@lists.php.net; Tue, 24 Sep 2013 14:01:40 -0500 Received: by mail-qa0-f46.google.com with SMTP id j7so2724321qaq.5 for ; Tue, 24 Sep 2013 12:01:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=81Z3oDRLtpDhXakkCcCZKYwmJaDwHRjXUzFAgabaG+I=; b=XptOdqKpXp6WfmfYOyYgJNNDKZ88i+aD5OxFJo2bMMVYZrgKyoOfwmytM49vNWD5Rn +zhp1mXmdcNABq16r61tbk75cAL7BJmQPV5Uj1rbsjtVHcYsdrAGQsa6OvOPvP9bcr6C 4eUfD7NkYJhfLfhmiiJJvwGkCqu4MXltd7LZb2no9yeMxQKY8JHbjv6V8PYJNlPtvc1Y Wfj7uj1UoEptTTVYezQvCipG/R8AvsJj5CNSAEsmWK7hOP/tZV3NUHMlozfjXpRrfZ12 gWm5rv42ML7F8HlO4AUs6hY8YyW4148zK+06P7v/YVQ+Ux06O/c9O5qSAeh+8mi5K5u2 mT9Q== X-Received: by 10.229.47.71 with SMTP id m7mr9846202qcf.25.1380049299166; Tue, 24 Sep 2013 12:01:39 -0700 (PDT) MIME-Version: 1.0 Reply-To: pierre@pcservice.co.za Received: by 10.49.132.1 with HTTP; Tue, 24 Sep 2013 12:01:09 -0700 (PDT) In-Reply-To: References: Date: Tue, 24 Sep 2013 21:01:09 +0200 Message-ID: To: Nicolas Grekas Cc: Joe Watkins , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a1133b3e43fde1a04e725c48a X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vinacomin.websitewelcome.com X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - pcservice.co.za X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (mail-qa0-f46.google.com) [209.85.216.46]:52824 X-Source-Auth: pierre@pcservice.co.za X-Email-Count: 3 X-Source-Cap: cGNzZXJ2aWM7cGllcnJlO3ZpbmFjb21pbi53ZWJzaXRld2VsY29tZS5jb20= Subject: Re: [PHP-DEV] RFC: Anonymous Classes From: pierre@pcservice.co.za (Pierre du Plessis) --001a1133b3e43fde1a04e725c48a Content-Type: text/plain; charset=ISO-8859-1 On 24 September 2013 14:51, Nicolas Grekas wrote: > What about allowing a "use" statement on these methods? > > $someFoo = "bar"; > > $object = new class{ > function method() use ($someFoo) { return $someFoo;} > } > > $object->method(); // "bar"; > I think the idea of anonymous classes is very useful. a use case that I recently encountered, is to override a specific method in a class. So instead of creating a new class that extends the original class, you can just use an anonymous class and override the methods that you want. E.G. You can to the following: use Symfony\Component\Process\Process; $process = new class extends Process { public function start() { /* ... */ } }; instead of the following: namespace My\Namespace\Process; use Symfony\Component\Process\Process as Base; class Process extends Base { public function start() { /* ... */ } } $process = new \My\Namespace\Process\Process; --001a1133b3e43fde1a04e725c48a--