类与函数 [英] Classes vs functions

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

问题描述

自从我第一次开始使用php以来,我一直在使用函数,但我已经

听到越来越多的关于课程的内容,我从未真正看过它

多了。我理解整个OO编程方面,但是有没有任何

的优势,而不仅仅是函数?我听说

这些类更好,因为它们只加载了他们需要的函数,

哪里有一个包含文件的函数,整个页面都被加载了,如果你只在某个页面上使用几个函数,那么即使是

,找不到任何官方的尽管如此。那么,这是真的吗?我应该开始迁移到使用类而不是函数吗?


-

VR

I''ve been using functions since I first started using php, but I''ve been
hearing more and more about classes, which I never really looked at that
much. I understand the whole OO programming aspect, but are there any
advantages to having classes as opposed to just functions? I''ve heard that
the classes are better because they only load the functions they need to,
where with an include file of functions, the whole page gets loaded, even
if you only use a couple functions on a certain page. I''ve searched around
and can''t find any "official" mention of this though. So, is that true and
should I start migrating to using classes instead of functions?

--
VR

推荐答案

vrillusions:
vrillusions:
自从我第一次开始使用php以来,我一直在使用函数,但是我我已经越来越多地听到了关于课程的内容,我从来没有真正看过那些课程。我理解整个OO编程方面,但是有没有任何优势,而不仅仅是函数?我听说过这些课程更好,因为他们只加载了他们需要的功能,其中有一个包含文件的函数,整个页面都被加载了,甚至如果您只在某个页面上使用几个函数。我已经搜索了
并且找不到任何官方的信息。尽管如此。那么,是真的
我应该开始迁移到使用类而不是函数吗?
I''ve been using functions since I first started using php, but I''ve been
hearing more and more about classes, which I never really looked at that
much. I understand the whole OO programming aspect, but are there any
advantages to having classes as opposed to just functions? I''ve heard
that the classes are better because they only load the functions they need
to, where with an include file of functions, the whole page gets loaded,
even
if you only use a couple functions on a certain page. I''ve searched
around
and can''t find any "official" mention of this though. So, is that true
and should I start migrating to using classes instead of functions?




不会。这对我来说听起来很混乱。 PHP显然不是无所不知的,因此
因此必须解析它所读取的所有源文件。

$ b $bAndréN?ss



No. That sounds rather confused to me. PHP obviously isn''t omniscient and
thus has to parse all the source files it reads in.

André N?ss


2003-12-11,vrillusions< vrillusions@not_this.neo.rr.com.invalid>写道:
On 2003-12-11, vrillusions <vrillusions@not_this.neo.rr.com.invalid> wrote:
自从我第一次开始使用PHP以来,我一直在使用函数,但我已经听到越来越多的关于类的知识了,我从来没有真正看过那些


如果您了解OOP,您应该看到_possible_优势(如果使用)

正确...(但如果您看到它们,为什么你有没有选择PHP?

难道J2EE看起来不合适吗?)

我听说过这类课程更好因为它们只是加载他们需要的功能,
使用包含文件的函数,整个页面加载,甚至
如果您只在某个页面上使用几个函数。我搜索了一下
并且找不到任何官方的尽管如此。那么,这是真的吗?
我应该开始迁移到使用类而不是函数吗?
I''ve been using functions since I first started using php, but I''ve been
hearing more and more about classes, which I never really looked at that
much. I understand the whole OO programming aspect, but are there any
advantages to having classes as opposed to just functions?

If you do understand OOP, you should see the _possible_ advantages if used
right... (But if you see them, why did you choose for PHP anyway?
Doesn''t J2EE seem more appropriate?)
I''ve heard that
the classes are better because they only load the functions they need to,
where with an include file of functions, the whole page gets loaded, even
if you only use a couple functions on a certain page. I''ve searched around
and can''t find any "official" mention of this though. So, is that true and
should I start migrating to using classes instead of functions?




一个人可以创建一个包含所有函数的真正大类。这将是一个愚蠢的,因为没有在不同的文件中创建功能组。


-

verum ipsum factum



One could make a really big class with all functions in it. This would
be as dumb as not making groups of functions, in separate files.

--
verum ipsum factum


vrillusions写道:
vrillusions wrote:
自从我第一次开始使用php以来,我一直在使用函数,但我已经听过了
越来越多的关于课程,我从来没有真正看过那么多。我理解整个OO编程方面,但是有没有任何优势,而不仅仅是函数?


我是这么认为的...但是在PHP中,你可以在没有OO的情况下做同样的事情。


我个人喜欢什么OO(一般情况下)它允许具有

相同概念的不同可替换实现,具有

统一表示。


请注意,你显然不需要在PHP中使用ADT的类,但是这个
不会给你多态(或者不那么容易)。现在你是否需要

这取决于你的应用程序和编码风格。自从我开始编程以来,大部分时间都使用(或多或少)OO语言,我可能会有点偏见! - )

另一个更具体PHP特点的是PHP没有任何

模块概念,类也可以用来模拟模块,因此

整理全局命名空间。

我听说过类更好,因为它们只加载了所需的功能,
带有函数的包含文件,整个页面如果你只在某个页面上使用几个函数,即使是
也会被加载。我搜索了一下
并且找不到任何官方的尽管如此。那么,这是真的


我从来没有听说过这样的事情,并且真的怀疑它甚至可能在

PHP中。


我应该开始迁移到使用类而不是函数吗?
I''ve been using functions since I first started using php, but I''ve been
hearing more and more about classes, which I never really looked at that
much. I understand the whole OO programming aspect, but are there any
advantages to having classes as opposed to just functions?
I think so... But in PHP, you can probably do the same thing without OO.

What I personnaly like w/ OO (in general) is that it allows to have
different substitutable implementations of a same concept, with a
uniform representation.

Note that you clearly don''t need classes to have ADTs in PHP, but this
won''t give you polymorphism (or not as easily). Now whether you need
this or not depends on your application and coding style. Having mostly
used (more or less) OO languages since I began programming, I''m may be a
bit biased !-)

Another point that is more PHP-specific is that PHP not having any
module concept, classes can also be used to emulate modules, thus
uncluttering the global namespace.
I''ve heard that
the classes are better because they only load the functions they need to,
where with an include file of functions, the whole page gets loaded, even
if you only use a couple functions on a certain page. I''ve searched around
and can''t find any "official" mention of this though. So, is that true
I''ve never heard of such a thing, and really doubt it''s even possible in
PHP.
and
should I start migrating to using classes instead of functions?




那是另一个问题,而且这个问题已经解决了对你...但你可能

如果你不需要它就不在乎。


我的2< euro> ;美分,

布鲁诺



That''s another problem, and this one is up to you... But you probably
shouldn''t care if you don''t have a need for it.

My 2 <euro>cents,
Bruno


这篇关于类与函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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