PHP - 函数内的函数。是好是坏? [英] PHP - Function inside a Function. Good or bad?

查看:118
本文介绍了PHP - 函数内的函数。是好是坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在PHP中另一个函数中定义一个函数是否是一件好事。是不是更好的定义它在功能(而不是内部)之前的表现。

解决方案

我认为你应该更关心可维护性,更少关注性能,特别是在这种情况下,两种解决方案之间的性能差异可能不是那么大,而维护性差异看起来很重要。



像Donald Knuth所说:


我们应该忘记小
的效率,比如97%的
时间:过早优化是所有邪恶的
根。


在这种情况下,这是完全正确的。 - )

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 of performances.

解决方案

I think you should care more about maintenability, and less about performance, especially in that kind of situation, where the difference in performances is probably not that big between the two solutions, while the difference in maintenability seems important.

Like Donald Knuth said :

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.

This is quite true, in this situation ;-)

这篇关于PHP - 函数内的函数。是好是坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆