functions.php vs OOP [英] functions.php vs OOP
问题描述
如果我在一个名为functions.php的文件中具有有用的函数的集合(足够简单) OOP的优势是什么?
if i have a collection of useful functions in a file called functions.php (easy enough) what would be the advantage of OOP?
我想学习它,但是它的深度很深,所以在我潜水之前,很高兴知道它是否有优势.我可以像接收变量一样轻松地将变量发送给函数.
I want to learn it, but its pretty in depth so before I dive it, would be nice to know if there is an advantage. I can send variables to the functions just as easily as I can receive them.
我有的例子 函数del_some_string($ x,$ y)//组成的函数从$ x中删除y个字母
example i have functions del_some_string($x,$y)// made up function to delete y number of letters from $x
为什么将它作为OOP会更好?
why would this be better as a OOP?
推荐答案
取决于函数的作用,如果您拥有一些通用数据,可以对这些数据进行各种操作以操纵相同的数据,则可能需要在类中对其进行建模.另一方面,如果您正在使用的所有数据都没有关系,那么使用OOP确实没有好处.
Depends on what the functions do, if you have some common data on which you do various operations to manipulate the same data you might want to model it in a class. On the other hand if all data you are working with has no relation with each other there is not really a benefit of using OOP.
例如,您提到的函数比类的成员更多是实用程序函数.
For example the function you mentioned is more a utility function than a member of a class.
这篇关于functions.php vs OOP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!