Re: PATCH: anonymous functions in PHP

From: Date: Tue, 20 Mar 2007 18:12:09 +0000
Subject: Re: PATCH: anonymous functions in PHP
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  Groups: php.internals 
Request: Send a blank email to internals+get-28487@lists.php.net to get a copy of this message
I've been wanting a true first-class callable type for a while. -Andrei On Mar 19, 2007, at 5:02 PM, Wez Furlong wrote:
The second possibility would be to make a first-class callable zval type which stores that information in the return value from the function declaration. The callable type would store a pointer to the op_array as well as a hash table to use to initialize the local scope of the function. Again, this would be created based on the $_SCOPES fixup information, and again, $_SCOPES['i'] would be rewritten as simply $i in the op_array. So the funcs array might look like this is var_dump()'d: 0 => callable('__anon_0', array('i' => 0)), 1 => callable('__anon_0', array('i' => 1)), 2 => callable('__anon_0', array('i' => 2)) Adding a type seems cleaner, but obviously requires more work as the rest of the internals need to understand what to do with it. A third possibility is similar to the second, but a bit less invasive. Create a callable class type to encapsulate that information. The rest of the internals would see $funcs[0] as an object, but the engine would know that calling it will invoke the appropriate function, prepping the local scope as described above. --Wez.


« previous php.internals (#28487) next »