Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28447 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10985 invoked by uid 1010); 19 Mar 2007 21:13:22 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 10970 invoked from network); 19 Mar 2007 21:13:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Mar 2007 21:13:22 -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:33565] helo=blobule.interjinn.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0A/02-01604-1FCFEF54 for ; Mon, 19 Mar 2007 16:13:21 -0500 Received: by blobule.interjinn.com (Postfix, from userid 2000) id 3D40D5AD1FB; Mon, 19 Mar 2007 17:13:22 -0400 (EDT) To: Stanislav Malyshev Cc: Wez Furlong , Sean Coates , internals@lists.php.net In-Reply-To: <45FEF9A5.4050409@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> <1174336464.24632.110.camel@blobule> <45FEF9A5.4050409@zend.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: InterJinn Date: Mon, 19 Mar 2007 17:13:21 -0400 Message-ID: <1174338801.24632.124.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:59 -0700, Stanislav Malyshev wrote: > > What about just having a function that allows retrieving variables from > > the parent scope? > > > > mixed seek_var( $name [, $levels=1, [ $startLevel=0 ] ] ) > > How you are going to know where "parent scope" is? It can even be not > existing anymore, or can be separated by any number of parameter > passing. Remember that the function is defined at compile-time, but > invoked at run-time by some other function. I guess I was primarily thinking in the context of the anonymous function being defined in your previous example. As such the parent scope is known (or at least can be expected), unless (unknown to me) within the internal C code the scope can change other than the hierarchy one would see visually while writing PHP code. From your example: On Sun, 2007-03-18 at 19:06 -0700, Stanislav Malyshev wrote: > > What happens if you do this: > $data = array("zoo", "orange", "car", "lemon", "apple"); > $rev = 1; > usort($data, function($a, $b) { return $rev?strcmp($a, $b):! strcmp($a, $b); }); > var_dump($data); # data is sorted alphabetically > We would have: Can we not expect that the lexical scope of the $rev is the immediate parent of the anonymous function at runtime? Obviously this could also work for normally defined functions if there's an expectation of the calling environment having some specific variable defined. 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. | `------------------------------------------------------------'