Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28441 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90943 invoked by uid 1010); 19 Mar 2007 20:34:19 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 90928 invoked from network); 19 Mar 2007 20:34:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Mar 2007 20:34:19 -0000 Authentication-Results: pb1.pair.com header.from=robert@interjinn.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=robert@interjinn.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain interjinn.com from 66.11.173.122 cause and error) X-PHP-List-Original-Sender: robert@interjinn.com X-Host-Fingerprint: 66.11.173.122 unknown Linux 2.5 (sometimes 2.4) (4) Received: from [66.11.173.122] ([66.11.173.122:45237] helo=blobule.interjinn.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C6/EF-01604-AC3FEF54 for ; Mon, 19 Mar 2007 15:34:19 -0500 Received: by blobule.interjinn.com (Postfix, from userid 2000) id 8BD0C5AD3D1; Mon, 19 Mar 2007 16:34:24 -0400 (EDT) To: Stanislav Malyshev Cc: Wez Furlong , Sean Coates , internals@lists.php.net In-Reply-To: <45FEEF52.1060002@zend.com> References: <86478A67-DCA2-4000-9EF0-DA4338E8389B@omniti.com> <45FDF031.4010508@zend.com> <45FE2312.1050506@zend.com> <45FED6D9.8030307@caedmon.net> <45FEDAE5.2010309@zend.com> <45FEE396.7040905@caedmon.net> <0757BDEA-65F5-4123-B647-060DCA84B4B0@omniti.com> <45FEEF52.1060002@zend.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: InterJinn Date: Mon, 19 Mar 2007 16:34:23 -0400 Message-ID: <1174336464.24632.110.camel@blobule> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Subject: Re: [PHP-DEV] PATCH: anonymous functions in PHP From: robert@interjinn.com (Robert Cummings) On Mon, 2007-03-19 at 13:15 -0700, Stanislav Malyshev wrote: > > I've been thinking about this on and off today too. > > Something along the lines of the following is more in the PHP spirit: > > > > $ver = phpversion(); > > $fancyVer = function () { lexical $ver; return "PHP $ver"; }; > > > > Where "lexical" is a keyword that means "inherit this variable from the > > current lexical scope". I'm not suggesting that this is a good name for > > the keyword, it's just something that springs to mind. > > How this is going to work? Variables are not interpreted by the compiler > now... > > > So, given some way to explicitly reference the scope where the function > > was "defined", what happens when you call $fancyVer after that scope has > > gone away: > > Exactly! That's why it is hard to do closures in PHP :) What about just having a function that allows retrieving variables from the parent scope? mixed seek_var( $name [, $levels=1, [ $startLevel=0 ] ] ) Returns the the value of the variable with name $name in the current of parent lexical scopes. By default the seek will only search for the variable in the current and immediate parent scopes but this can be tailored to meet any particular need including searching to the top by setting $levels to -1. Additionally by setting $startLevel greater than 0, the search can be confined to scopes outside of the current lexical scope. If the request variable is not found then E_NOTICE is generated and null is returned. Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'