Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83680 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22708 invoked from network); 24 Feb 2015 18:16:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Feb 2015 18:16:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=pjsturgeon@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pjsturgeon@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.46 as permitted sender) X-PHP-List-Original-Sender: pjsturgeon@gmail.com X-Host-Fingerprint: 209.85.215.46 mail-la0-f46.google.com Received: from [209.85.215.46] ([209.85.215.46:36153] helo=mail-la0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/20-20073-4FFBCE45 for ; Tue, 24 Feb 2015 13:16:21 -0500 Received: by labgq15 with SMTP id gq15so27759908lab.3 for ; Tue, 24 Feb 2015 10:16:17 -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=ifG77oA/r9wiNJGR+Wp2Km1pekmNG40r7Xl6sf/gVOU=; b=WcmN+XRrXoDAAVSgv9ZPSmHuAgpccifDood7kxrZy5/z1edUyucZCzrHJrSFeO2OFV qKG4acclHTOxqvFCxEM56J8V+OhupNldcj/tn0rgMWQROqZW3yvr57QWSHofR8zxhBEw lbuC1qatNBn0eDk2A7B3qn262m+ROaWT8fikp7PIkQCGoc1q0lsnV4RCwOTtptg7YdwJ Rps1chuKn5BxeQbF4nSF0UCWV5s732wUVAh8r4lOrVzRV3369NrovQpO6SBfvHT8fiRA NyKoL182YbIXGIxKBpcoyK8qJ9Ec3Fl/F+9OagN02j9wa/gLCP6XOMdnrxbP8NaY4RnV TtKQ== MIME-Version: 1.0 X-Received: by 10.112.85.165 with SMTP id i5mr8458948lbz.7.1424801777818; Tue, 24 Feb 2015 10:16:17 -0800 (PST) Received: by 10.114.26.34 with HTTP; Tue, 24 Feb 2015 10:16:17 -0800 (PST) In-Reply-To: References: Date: Tue, 24 Feb 2015 13:16:17 -0500 Message-ID: To: Mike Willbanks Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Anonymous Classes From: pjsturgeon@gmail.com (Philip Sturgeon) On Tue, Feb 24, 2015 at 12:21 PM, Mike Willbanks wrote: > > > 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. >> >> It was declined for PHP 5 some time ago, and has returned now to try for >> PHP 7. >> >> The usage of anonymous classes to some will be instantly offensive, >> but really it comes down to the use case. The usage of anonymous >> functions compared to declared functions is pretty much the exact same >> thing as anonymous classes. >> >> Other than examples on the RFC, Fractal would certainly be happy to >> have them: http://fractal.thephpleague.com/transformers/ > > > I would also find myself to be a very happy consumer of this. It can > provide the opportunity of getting rid of a large amount of boilerplate. In > addition, there has been several times when implementing single use > extensions for say view libraries (Plates extensions comes to mind) or > Plugin handling for things like Zend Framework 2 and there has been several > times I utilize a closure with an array to get around having an object > simply due to you want to have a callback but with some form of definition. > I think there is a very large use case here and something that would be a > great addition to the language. Sure, I could make a class and extend it > just like this would do but for the convenience of the implementation it is > sometimes better to do a simple closure. > >> Defining a class properly is certainly still going to be the majority >> of uses of classes in PHP. That helps with the Optimizer, and helps >> code reuse. >> >> Sadly due to the way in which people have had ONE CLASS ONE FILE >> drilled into their head since PEAR and continuing through Zend and >> PSR-0, it can become a PITA to add some simple functionality if a >> small class is needed for one tiny thing. > > > I see the point here, but the argument to me seems void. Nothing wrong with > a simple class one file for a small class. > Something doesn't have to be "wrong", another approach can just be more convenient, or handy for different use cases. One class one file can be rather slow depending on the autoloader setup, and depending on whether zend optimizer is enabled or not. For a distributed application running on mostly crap shared hosting, relying on Zend Optimizer is not an option, so the more of these little one-class one-file situations you have the worse it becomes. This RFC offers a solution for people that is not "Jam a bunch of these classes at the top of the current file" or "Make a whole load of one-time use classes to avoid that mess, plus people will snort and shame you for failing to follow decade old best practices."