How can I use PHP closure function like function() use() on PHP 5.2 version?

前端 未结 3 440
一向
一向 2021-01-27 12:48

How can I use PHP closure function like function() use() on PHP 5.2 version as it has no support for anonymous functions?

Currently my code is something like below

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-27 13:25

    Php supports anonymous functions since 5.3.0, read about it in manual.

    You could use create_function but you should avoid this (for example because of this comment) and it's practically the same as eval... One bad enclosure and you'll make your sources vulnerable. It's also evaluted on runtime, not on compilation time what can decrease performance and may cause fatal error in the middle of included file.

    Rather declare that function somewhere, it'll be more effective.

提交回复
热议问题