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. | `------------------------------------------------------------' -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php