Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38324 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13077 invoked from network); 17 Jun 2008 12:24:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jun 2008 12:24:55 -0000 Authentication-Results: pb1.pair.com header.from=chris_se@gmx.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=chris_se@gmx.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.net designates 213.165.64.20 as permitted sender) X-PHP-List-Original-Sender: chris_se@gmx.net X-Host-Fingerprint: 213.165.64.20 mail.gmx.net Linux 2.5 (sometimes 2.4) (4) Received: from [213.165.64.20] ([213.165.64.20:46226] helo=mail.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1D/09-61252-41DA7584 for ; Tue, 17 Jun 2008 08:24:54 -0400 Received: (qmail invoked by alias); 17 Jun 2008 12:24:49 -0000 Received: from p54A173C3.dip.t-dialin.net (EHLO chris-se.dyndns.org) [84.161.115.195] by mail.gmx.net (mp004) with SMTP; 17 Jun 2008 14:24:49 +0200 X-Authenticated: #186999 X-Provags-ID: V01U2FsdGVkX19nwWID5ABnMQJWFp7jbCMnbp6wUoiZXep1TgxWc3 R4qzWb7s5f9IoQ Received: from [192.168.0.175] (HSI-KBW-091-089-005-213.hsi2.kabelbw.de [91.89.5.213]) by chris-se.dyndns.org (Postfix) with ESMTP id 82FB610506 for ; Tue, 17 Jun 2008 14:14:15 +0200 (CEST) Message-ID: <4857ACE1.3050501@gmx.net> Date: Tue, 17 Jun 2008 14:24:01 +0200 User-Agent: Thunderbird 2.0.0.14 (X11/20080421) MIME-Version: 1.0 To: php-dev List References: <4856A547.3080801@gmx.net> <1961603263.20080617120320@marcus-boerger.de> In-Reply-To: <1961603263.20080617120320@marcus-boerger.de> X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 Subject: Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP From: chris_se@gmx.net (Christian Seiler) 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. Regards, Christian