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 :)

This could perhaps be solved by taking a reference to $ver when the function is bound, but I don't know enough about the ZE to understand the implications of that; it would probably require a bit more state

$ver would not even exist when we compile it - $ver appears in run-time and we want function to be created in compile-time!

--
Stanislav Malyshev, Zend Products Engineer
[EMAIL PROTECTED]  http://www.zend.com/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to