Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38313 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68265 invoked from network); 17 Jun 2008 07:45:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jun 2008 07:45:51 -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 Received: from [213.165.64.20] ([213.165.64.20:52230] helo=mail.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2D/01-61252-EAB67584 for ; Tue, 17 Jun 2008 03:45:50 -0400 Received: (qmail invoked by alias); 17 Jun 2008 07:45:46 -0000 Received: from p54A173C3.dip.t-dialin.net (EHLO chris-se.dyndns.org) [84.161.115.195] by mail.gmx.net (mp068) with SMTP; 17 Jun 2008 09:45:46 +0200 X-Authenticated: #186999 X-Provags-ID: V01U2FsdGVkX1/mPSB4ER/mkcFceA8+ci7jroGOzI3ewS68UBLq/G vsE08uMcM0hNUI 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 7B2BF10D64 for ; Tue, 17 Jun 2008 09:35:12 +0200 (CEST) Message-ID: <48576B7A.5070504@gmx.net> Date: Tue, 17 Jun 2008 09:44:58 +0200 User-Agent: Thunderbird 2.0.0.14 (X11/20080421) MIME-Version: 1.0 To: internals@lists.php.net References: <4856A547.3080801@gmx.net> <4856B752.1040500@gmx.net> <200806162257.24141.larry@garfieldtech.com> <7dd2dc0b0806162257t15f679c1t2d9e77221144f340@mail.gmail.com> In-Reply-To: <7dd2dc0b0806162257t15f679c1t2d9e77221144f340@mail.gmail.com> 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! > class Dynamic { > private $someVar = 5; > /// adding a function to instances from within the class > public function addMethodAtRuntime() { > $this->dynamicFunc1 = function() { > return $this->someVar; // expected to work > } > } > } > > /// invoking dynamically added methods > /// (anticipated behavior given above definitions) > $dynamic->addMethodAtRuntime(); > echo $dynamic->dynamicFunc1(); // 5 This will not work - for the same reason as this does not work: class SpecialChars { public $process = 'htmlspecialchars'; } $sc = new SpecialChars (); var_dump ($sc->process ('<>')); // call to undefined ... On the other hand, the following will work: $sc = new SpecialChars (); $processor = $sc->process; var_dump ($processor ('<>')); // string(8) "<>" The same with closures: echo $dynamic->dynamicFunc1(); // call to undefined ... $func = $dynamic->dynamicFunc1; echo $func (); // 5 echo call_user_func ($dynamic->dynamicFunc1); // 5 As I sead in my other mail: I don't see closures as a method for somehow making it possible to extend classes dynamically - if you want that, use runkit. Regards, Christian