为什么PHP被认为是面向对象的? [英] Why is PHP considered Object Oriented?

查看:96
本文介绍了为什么PHP被认为是面向对象的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读OOP的定义,无法理解为什么PHP被认为是面向对象的.

I have been reading around the definition of OOP and couldn't get why PHP is considered object oriented.

这可以做些PHP的基本级别"不是,而更高级的功能吗?

Can this have anything to do that the "basic level" of PHP isn't and more advanced features are?

推荐答案

几乎所有允许您创建和实例化类的语言都可以视为面向对象的.

Almost any language that allows you to create and instantiate classes can be considered object oriented.

PHP具有这些功能,但并没有真正扩展它们.您可以使用OOP来帮助您的代码,但这不是必需的. Java,C#和C ++几乎不允许您编写非OO代码,因为所有内容都必须在类中.

PHP has these capabilities, but doesn't really stretch them. You can use OOP to help your code, but it isn't required. Java, C#, and C++ barely allow you to write non-OO code, as everything must be in a class.

这是否可以做些PHP的基本级别",而没有更高级的功能呢?

Can this have anything to do that the "basic level" of PHP isn´t and more advanced features are?

您几乎可以说所有OO语言. OO代码的一般定义是在其中创建类并在代码中实例化它们,然后从其他类调用它们的方法的地方.没有什么能阻止您仅使用静态方法或带有运行"方法的超类,而该运行"方法仅调用该类内部的其他方法,而这两种方法肯定都不是面向对象的.据我所知,没有任何语言说您必须创建类并实例化它们,否则您将被放逐!"即使存在,我怀疑由于控制缺陷,它们是否会非常接近主流.

You could say that about just about any OO language. The general definition of OO code is where you create classes and instantiate them in your code, calling methods on them from other classes. Nothing stops you from using only static methods or one super class with a 'run' method that only calls other methods inside the class, both of which would definitely NOT be object oriented. As far as I know, there aren't any languages that say "You must create classes and instantiate them or you will be banished!" Even if there were, I doubt they would get very close to mainstream because of the control-freakness.

初学者经常学习基础知识,同时将所有代码放入一种仅在程序状态被调用的方法中.一旦他们获得了诸如方法和类之类的更多高级"功能,便会获得其他选择. :D

Beginners often learn the basics while putting all their code in just one method that gets called at the stat of the program. Once they get to more 'advanced' features like methods and classes, they are offered other options. :D

这篇关于为什么PHP被认为是面向对象的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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