How to use anonymous functions before PHP 5.3? [duplicate]

别说谁变了你拦得住时间么 提交于 2019-12-24 18:09:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!