Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83675 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9719 invoked from network); 24 Feb 2015 16:21:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Feb 2015 16:21:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=leverton@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=leverton@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.181 as permitted sender) X-PHP-List-Original-Sender: leverton@gmail.com X-Host-Fingerprint: 209.85.192.181 mail-pd0-f181.google.com Received: from [209.85.192.181] ([209.85.192.181:46149] helo=mail-pd0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3B/B0-05669-115ACE45 for ; Tue, 24 Feb 2015 11:21:38 -0500 Received: by pdjy10 with SMTP id y10so34306301pdj.13 for ; Tue, 24 Feb 2015 08:21:35 -0800 (PST) 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:content-type; bh=L2UsyqMiQ8JbfDcWivkkWH1aK8VIwrKuTvxf32aeSls=; b=MIsXwJ4fRp30U8OeULQIrPEziWhpsgiDtRT7Ag7kyy2m3Qh25O39sbOFu9CjcxWmCf x6as5COKgRvz65SKR3DzMmrMorxJqV16lMuy0uD1tbVfLk5ZFr0WheVrw0Avn7eaTTTU DLQ74JIztAzX0yMtBGfmH1DEUpiyJfwODQ2NkbaFaXFjNgmKX1tQ8ahaduvPTLF27Pw5 vd2HcIg35TKLTQYqNWzPXPMYkWwImokzTMpuoOqQ3YTiSXs49nu73MvsUBDBBZTdD2wQ FjKXkFghmOBY4dk62CzHcQavPrp217Q72KfCR1PJA/uyfy/i1ZGy/ijrC29so0FeYQll 2n7Q== MIME-Version: 1.0 X-Received: by 10.70.88.142 with SMTP id bg14mr30195241pdb.46.1424794895196; Tue, 24 Feb 2015 08:21:35 -0800 (PST) Received: by 10.70.65.130 with HTTP; Tue, 24 Feb 2015 08:21:35 -0800 (PST) In-Reply-To: References: Date: Tue, 24 Feb 2015 10:21:35 -0600 Message-ID: To: Philip Sturgeon Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Anonymous Classes From: leverton@gmail.com (Matthew Leverton) On Tue, Feb 24, 2015 at 7:52 AM, Philip Sturgeon wrote: > Good day! > > https://wiki.php.net/rfc/anonymous_classes > > There's a little RFC + patch that Joe Watkins put together, and as > before with the ArrayOf RFC, I'll be helping out. > > So, lets get this discussion rolling. > Anonymous classes open up slightly new ways to do things. I like to write a lot of small classes for the purposes of DI and re-usability. Because of that, the code often looks like: $foo = new Foo($depend1, $depend2, function() { return 'my custom behavior'; }); That's fine when there's only one callback needed, but beyond that it breaks down. This becomes more readable: abstract class Foo { ... } $foo = new class($depend1, $depend2) extends Foo { public function doFoo() { } public function doBar() { } } These cases for me are always single-use for the scope of the application, and often it's inside configuration blocks that are custom per environment. I have no need to name the class other than PHP doesn't support anonymous ones. I'm +1 on the concept, depending on what the maintenance impact that this would bring to PHP's core. There are enough other ways to accomplish the same goals that I don't think this is "must have", even though I'd definitely use it. Regarding this syntax (from other discussions on the list): $foo = class { }; I think if such a thing were supported, maybe $foo would just be a ReflectionClass object. (I haven't really thought that one through...) -- Matthew Leverton