Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38328 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18228 invoked from network); 17 Jun 2008 19:10:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jun 2008 19:10:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.94.56 as permitted sender) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 85.214.94.56 aixcept.net Linux 2.6 Received: from [85.214.94.56] ([85.214.94.56:41767] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 70/D4-24906-53C08584 for ; Tue, 17 Jun 2008 15:10:47 -0400 Received: from MBOERGER-ZRH (unknown [193.142.125.1]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id 3279311EFF9; Tue, 17 Jun 2008 21:10:42 +0200 (CEST) Date: Tue, 17 Jun 2008 21:10:38 +0200 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <1178748433.20080617211038@marcus-boerger.de> To: Christian Seiler , Johannes Schlueter CC: php-dev List In-Reply-To: <4857ACE1.3050501@gmx.net> References: <4856A547.3080801@gmx.net> <1961603263.20080617120320@marcus-boerger.de> <4857ACE1.3050501@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP From: helly@php.net (Marcus Boerger) Hello Christian, Johannes, Tuesday, June 17, 2008, 2:24:01 PM, you wrote: > Hi Marcus, > I now have revised my patch to include your suggestions: > http://www.christian-seiler.de/temp/closures-php-5.3-2008-06-17-2.diff > The changes to the previous version: > - \0 at the start of the compiled lambda function name is dropped. > - lambdas which are class members are now marked as final > - the generated name of the lambda is now also stored within the > op_array (before op_array->function_name was simply "lambda") > - your suggestions for code cleanups in zend_compile.c >> Actually how does it integrate with reflection? > Consider the following class: > class Example { > private $x = 0; > public function getIncer () { > return function () { > $this->x++; > }; > } > public function show () { > $this->reallyShow (); > } > protected function reallyShow () { > echo "{$this->x}\n"; > } > } > Running > Reflection::export(new ReflectionClass('Example')); > will yield (among other things): > - Methods [4] { > Method [ public method getIncer ] { > @@ /home/christian/dev/php5.3/c-tests/reflection.php 6 - 10 > } > Method [ final public method > __compiled_lambda_/home/christian/dev/php5.3/c-tests/reflection.php_0 ] { > @@ /home/christian/dev/php5.3/c-tests/reflection.php 7 - 9 > } > Method [ public method show ] { > @@ /home/christian/dev/php5.3/c-tests/reflection.php 12 - 14 > } > Method [ protected method reallyShow ] { > @@ /home/christian/dev/php5.3/c-tests/reflection.php 16 - 18 > } > } > So lambda functions appear simply as additional methods in the class, > with their generated name. > Of course, the ReflectionMethod / ReflectionFunction classes could be > extended so that it provides and additional method isLambda() in order > to determine whether a function actually is a lambda function. But I'd > rather do that in a separate step and a separate patch. Yep, Reflection details can and should be addressed separately. I think the next step is confirming with the rest of the core team that we all ewant this. IMO it has often enough been requested and your patch solves every tiny piece that was missing so far. And if people agree then unfortunately you need to provide a patch for HEAD first. Actually you could do so just now. Johannes, what's your take on this one for 5.3? Best regards, Marcus