Is there an alternative to anonymous functions for versions of PHP previous to 5.3.0?
+4
A:
There is create_function but it generally isn't recommended. If you're using OOP, you'd be better off defining a one-off private member to use with a callback instead.
Jani Hartikainen
2010-09-12 11:19:13
Also, the result of create_function will not be garbage collected. So it's basically a memory leak.
WardB
2010-09-12 12:35:38
+2
A:
There are two choices.
First is to create a function, inside a function. Unfortunately, it will pollute the global namespace.
The second choice is to use create_function.
Yorirou
2010-09-12 11:20:59
That wouldn't make the inner function an anonymous function... just a function declared inside a function.
BoltClock
2010-09-12 11:24:36