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.
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:
^^^^
I meant code references of course.
-Sterling
"Science is like sex: sometimes something useful comes out, but that is not the reason we are doing it." - Richard Feynman
Anything that create_function() doesn't do?
Zeev
At 16:16 19/05/2003, Sterling Hughes wrote:
Quoted text · 18 lines
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.
Excuse my ignorance, but how does this differ from the features offered by create_function? (Other than having nicer aesthetics.)
Quoted text · 5 lines
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;
};