I've been reading on the new features of PHP 5.3, and one of the major features are closures.Unless I'm very badly mistaken, the PHP developers are either:
a) confusing closures with just anonymous functions
b) the closures are broken in PHP 5.3.1 in which I'm testingFrom what wikipedia says closures are the mechanism of anonymous functions plus the binding of the function's parent's scope variables to the function's scope. The last part seems broken in PHP.I've checked PHP bugs, and found nothing about this, strangely.Here's how I'm testing:\[code\]<?phpfunction getFun() { $x = 2; return function() { return $x; };}$f = getFun(); // getFun()(); doesn't work -.-var_dump($f()); // $f() == null\[/code\]In languages that actually implement closures, it returns 2:\[code\]def f(): x = 2 return lambda: xprint(f()()) # prints 2\[/code\]and\[code\]alert((function() { var x = 2; return function() { return x; };})()()); // alerts 2\[/code\]So, am I wrong or?
a) confusing closures with just anonymous functions
b) the closures are broken in PHP 5.3.1 in which I'm testingFrom what wikipedia says closures are the mechanism of anonymous functions plus the binding of the function's parent's scope variables to the function's scope. The last part seems broken in PHP.I've checked PHP bugs, and found nothing about this, strangely.Here's how I'm testing:\[code\]<?phpfunction getFun() { $x = 2; return function() { return $x; };}$f = getFun(); // getFun()(); doesn't work -.-var_dump($f()); // $f() == null\[/code\]In languages that actually implement closures, it returns 2:\[code\]def f(): x = 2 return lambda: xprint(f()()) # prints 2\[/code\]and\[code\]alert((function() { var x = 2; return function() { return x; };})()()); // alerts 2\[/code\]So, am I wrong or?