3 ms·
There is a difference between a closure and a lambda. PHP's create_function() implemented lambdas in PHP version 4.0.1 which was released in June 2000. 5.3 adde
by rll 14y ago
There is a difference between a closure and a lambda. PHP's create_function() implemented lambdas in PHP version 4.0.1 which was released in June 2000. 5.3 added closures.
- TylerE 14y agocreate_function is not equivalent to a python lambda. It's just a function for creating other functions. The key thing with a lambda in python is that it is defined at the usage site. so you can do: filter(lambda x: x > 42, mylist) Whereas in php that would be: $mylambda = create_function('$x','return $x > 42;'); filter($mylambda, $mylist); Yes, the usage strings as code adds yet another level of WTF to this example.
- rll 14y agoIt is still an anonymous function.
- papsosouid 14y agoYou said "lambda was added to PHP in June 2000". That is clearly not the case, and now you are trying to play semantic games to pretend you are still right. The function create_function() is not lambdas. It isn't even anonymous functions, they are still named, you just don't know the name. You can easily get a duplicate function error from using create_function(), which means it is most certainly not anonymous. Note that php.net/create_function even points you to their page on actual anonymous functions, which they erroneously claim are the same as closures.