PHP - Function inside a Function. Good or bad?

后端 未结 4 1468
有刺的猬
有刺的猬 2020-12-30 01:41

I would like to know if it is a good thing to define a function inside another function in PHP. Isn\'t it better to define it before the function (and not inside) in terms o

4条回答
  •  粉色の甜心
    2020-12-30 01:59

    There are multiple reasons against it:

    • The documentation of the inner function will not be parsed.
    • The inner function only exists after the outer function has been called (but even outside the scope of the outer function afterwards)
    • It is hard to read (because it is not seen commonly)
    • The only advantage I could think of is defining a callback, but this is better done with create_function() () or closures (>=PHP5.3)
    • If you're concerned about performance on this level, you should really be using another language

提交回复
热议问题