Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69346 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8691 invoked from network); 26 Sep 2013 10:16:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Sep 2013 10:16:03 -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:26523] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 11/7B-46303-26904425 for ; Thu, 26 Sep 2013 06:16:02 -0400 To: internals@lists.php.net,Nicolas Grekas Message-ID: <5244095F.3090005@php.net> Date: Thu, 26 Sep 2013 11:15:59 +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> <5242ADAE.2080007@php.net> <5242E88D.90407@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/26/2013 10:28 AM, Nicolas Grekas wrote: > I think what Terence was talking about is more like this: > > class A > { > } > > class AProxifier > { > protected function protectedMethod() {...} > > function getAProxy() > { > return new class extends A { /* How do you call > AProxifier->protectedMethod() here? */ }; > } > } > > This is possible with anonymous functions, that's a big feature of PHP5.4. > And for the same reasons might be expected here too? > I don't have the answer, just raising the point. > > > (new class ... >>> protected $value; >>> public function __construct($value) >>> { >>> $this->value = $value; >>> } >>> >>> public function doSomething() >>> { >>> echo $this->value; >>> })($val) >>> >> > > Btw, I can't get used to ($val) beeing at the end of the declaration. I > feel it very confusing. > > Nicolas > If you need access to the methods in AProxifier then why does the anonymous class extend A, you should extend AProxifier as you would with any other class. class A { public function __construct(/* ctor args*/) { /* ctor statements */ } protected function protectedMethod() { /* protected method */ } public function getProxy() { return new class extends A { /* proxy stuff */ } (/* ctor args */); } } For the following reasons the syntax should remain as it is: It keeps the number of conflicts in the parser the same (%expect 3) It is consistent with anonymous function calls - args after definition ... It does not make sense to pass arguments to a constructor that might not yet be declared It is the simplest syntax to implement .. and so less margin for error, easier to maintain in the future ... Cheers Joe