Let me see if I'm understanding you correctly, because that sounds like the 
line I'd been thinking along.

----------
function baz() {

  $var = 5;

  $foo = function($a, $b) {
    lexical $var;
    return $a + $b + $var;
  }

  return $foo;
}

$func = baz();

function bar($func) {
  return $func(2, 3);
}

echo bar($foo); // prints 10
----------

Right?  Would it be possible to push the heavy lifting onto the compiler 
rather than runtime in the above case?

I'm assuming that making the function above GC-able would be a herculean task 
at this point, based on previous comments, but I do not actually know myself.

On Monday 17 December 2007, Jeff Moore wrote:
> Hello,
>
> Reading the prior discussion, I think either $_SCOPE['x'] or the
> lexical $x syntax is fine for accessing local variables in the
> enclosing scope.   But closures also should also support $this and
> static:: when the closure is defined in a method.
>
> I think a solution for closures should add a new variable type.  That
> way, the code can compiled at compile time, while the enclosing
> context (local variables plus $this for methods) can be captured at
> run time in the new variable type.  Also, when the closure value is
> garbage collected, the references to the enclosing scope and object
> instance can also be freed.
>
> Additionally, the callback psuedo-type could be promoted to the new
> type, with the string or array representation converted when
> required.  It wouldn't be necessary, but a callback literal along the
> lines of Array() could also be added to make the conversion
> unnecessary.  I find the following to be easier to understand:
>
> set_error_handler(Callback("foo"));
>
> Than
>
> set_error_handler("foo");
>
> The current syntax would still work because of automatic type
> conversion.
>
> Best Regards,
>
> Jeff


-- 
Larry Garfield                  AIM: LOLG42
[EMAIL PROTECTED]               ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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

Reply via email to