Hi!

First, a comment from haskell-land:
http://www.haskell.org/pipermail/haskell-cafe/2008-June/044533.html
http://www.haskell.org/pipermail/haskell-cafe/2008-June/thread.html#44379

Thanks for the links, very interesting. Even a couple of comments in the thread going beyond "PHP sucks" and really discussing the matter. :)
Best account is this:

* A closure must only keep alive the varables it references, not the
whole pad on which they are allocated
[Check]
* A closure must be able to call itself recursively (via a
higher-order function typically)
[Check, since you can use variable you assigned closure to inside the closure, if I understand correctly]
* Multiple references to the same body of code with different bindings
must be able to exist at the same time
[Check]
* Closures must be nestable.
[Dunno - does the patch allow nesting and foo(1)(2)?]

Getting the same behaviour out of PHP should not be as difficult as this:

Well, I don't see any other way if you use references. Variables _are_ mutable in PHP. You could, of course, use copies, but then you'd lose ability to update. Maybe if we drop "lexical" and use Dmitry's proposal of

$arr[$i] = function () ($i) { return $i; };

where ($i) would be copy, (&$i) would be by-ref, then it'd be easier to control it. I know function()() is weird, but not everybody likes lexical either :) Maybe we can do lexical &$y, but that looks weird too...

Of course this would make lexical behave quite differently from global in this

I wouldn't spend too much thought on making lexical work like global. global is for different purpose (and with $GLOBALS is obsolete anyway :)
--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED]   http://www.zend.com/
(408)253-8829   MSN: [EMAIL PROTECTED]

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

Reply via email to