Re: Re: PATCH: anonymous functions in PHP

From: Date: Mon, 17 Dec 2007 23:41:52 +0000
Subject: Re: Re: PATCH: anonymous functions in PHP
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-34073@lists.php.net to get a copy of this message
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

« previous php.internals (#34073) next »