Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69311 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86321 invoked from network); 24 Sep 2013 11:23:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Sep 2013 11:23:30 -0000 X-Host-Fingerprint: 217.114.215.11 experimentalworks.net Date: Tue, 24 Sep 2013 07:23:29 -0400 Received: from [217.114.215.11] ([217.114.215.11:7526] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 19/E0-15989-13671425 for ; Tue, 24 Sep 2013 07:23:29 -0400 To: internals@lists.php.net References: User-Agent: slrn/pre1.0.0-18 (Linux) Message-ID: X-Posted-By: 217.114.215.11 Subject: Re: [PHP-DEV] RFC: Anonymous Classes From: dsp@php.net (David Soria Parra) Lazare Inepologlou schrieb: > I use anonymous classes very frequently in Java and in C#, and I would say > that they are quite useful. However the examples given in the RFC are > really bad ones. Why on earth would you need a constructor for an anonymous > class? Anonymous classes are used to implement quickly some interface. > Frankly, constructors are not part of any interface. Besides a constructor > is totally useless in an anonymous class as it will never be called after > the object is created. The need for anonymous classes in Java mostly comes from implementing interfaces on demand due to the lack of lamdas and the requirements of a strongly typed language. PHP has lambdas and it doesn't require you to match typing. Therefore I think the preferred way for most of the use cases is to use a lambda or if a bigger implementation is necessary, to give it a name. Due to namespacing you don't pollute the global scope anyway. Therefore I don't see much reason left as to why add anonymous classes and I really have a hard time finding a use case, except for trying to write PHP as you would write Java (which most likely is a bad idea). - David