问题
I have a class that uses 5.3 feature anonymous function (https://github.com/JeffreyWay/Easy-WordPress-Custom-Post-Types/blob/master/jw_custom_posts.php), but there is a problem, on the server I can not upgrade to 5.3. Is there any simple workaround to get rid of anonymous functions or do I need to rewrite whole class?
回答1:
You have two options:
- Change the hosting with PHP version supporting anonymous functions
- Re-write your code so it works with version of PHP you have
回答2:
A workaround for pre PHP 5.3 is to use create_function().
It is ugly as hell and akin to eval()
, but it's closest to functionality without defining another function and passing a pointer to it.
来源:https://stackoverflow.com/questions/9554707/how-to-use-anonymous-functions-before-php-5-3