Code References
| From: | Sterling Hughes | Date: | Mon, 19 May 2003 13:16:33 +0000 |
| Subject: | Code References | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-1698@lists.php.net to get a copy of this message | ||
Hi,
I figure I'll just throw this out into the wilderness, I want closures
and function pointers in PHP. In other words I want the ability to do:
$var = function ($a, $b) {
return $a + $b;
};
And then $var can contain a code reference to the anonymous function.
Having code references is an infinitely useful feature in my experience,
and I know other people have some really cool uses of closures for
lightweight templating (with mod_perl.) [1]
I'd also like function pointers, which are optimized callbacks of some
sort, so you can go:
function my_compare($a, $b) {
if ($a > $b) return 1;
if ($a < $b) return -1;
return 0;
}
sort($ar, <my_compare>);
And compare doesn't need to be resolved at runtime, but rather can be a
compile time feature.
-Sterling
[1] I say code references on purpose. This doesn't need to mean full
fledged closures, which are probably overkill (although, they would be
nice too ;)
--
"That stuff's easy compared to installing Horde"
- Alan Knowles, In response to my applause for creating a LALR
parser for PHP.