Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69335 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83205 invoked from network); 25 Sep 2013 09:32:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Sep 2013 09:32:34 -0000 X-Host-Fingerprint: 80.4.21.210 cpc22-asfd3-2-0-cust209.1-2.cable.virginmedia.com Received: from [80.4.21.210] ([80.4.21.210:12921] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 20/C0-14049-1BDA2425 for ; Wed, 25 Sep 2013 05:32:33 -0400 To: internals@lists.php.net,Terence Copestake Message-ID: <5242ADAE.2080007@php.net> Date: Wed, 25 Sep 2013 10:32:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 References: <5241F11C.5080707@php.net> <008301ceb967$b49ab190$1dd014b0$@tutteli.ch> <524205D8.8000608@php.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 80.4.21.210 Subject: Re: [PHP-DEV] RFC: Anonymous Classes From: krakjoe@php.net (Joe Watkins) On 09/25/2013 09:59 AM, Terence Copestake wrote: > I'm growing to like the idea myself. It may create new opportunities for > bad practices, but I don't think it's the concern of internals to police > how people may or may not use a feature. There are also I think a few > things that would need to be addressed before this would be ready for the > real world. For example: > > 1) As hinted at previously, the "use" statement. Doing this per-method as > suggested would be less ambiguous than applying to the whole class - and > would also prevent pollution. > > 2) Transparency between an anonymous class and the class in which it is > defined (if any). One thing I found very restrictive about closures back in > 5.3 was the lack of $this support. I can imagine that missing functionality > being similarly restrictive for these new anonymous classes. Obviously > $this itself will be reserved for use by the anonymous class, which means > there would need to be an alternative. Passing in a variable is one thing, > but as it stands the anon class would then only have public access. > Something like $class with similar behaviour to $this could be an option. > > In Java I believe anonymous classes have the same scope as the method in > which they're defined. Would something like this or similar be feasible and > permissible in PHP? > 1) Anonymous classes in PHP would support a constructor, so I don't see the need for use to be utilized here, it would just clutter declarations and the patch. 2) Again, constructors can be used, and is less confusing than introducing a new variable, but I'm open to persuasion if the idea is liked in general ... Well, it's likely possible to introduce a shared kind of scope, but I don't really think it's necessary, for the same reasons as 1) and 2).