为什么不在PHP中使用“保护”或“私有”? [英] Why not use 'protected' or 'private' in PHP?

查看:80
本文介绍了为什么不在PHP中使用“保护”或“私有”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Joomla框架,并且我注意到它们使用约定来指定私有或受保护的方法(它们前面加了下划线 _ 方法名称),但它们未明确声明任何方法 public private 受保护的。为什么是这样?它与可移植性有关吗? 公共私有受保护的关键字不可用在旧版本的PHP中?

I've been working with the Joomla framework and I have noticed that they use a convention to designate private or protected methods (they put an underscore "_" in front of the method name), but they do not explicitly declare any methods public, private, or protected. Why is this? Does it have to do with portability? Are the public, private, or protected keywords not available in older versions of PHP?

推荐答案

公开,私有和受保护是PHP5关键字。不幸的是,PHP4的安装量仍然很高(尤其是在共享托管服务中)。

public, private and protected are PHP5 keywords. unfortunately, PHP4 still has a very high install base (especially amongst shared hosting services).

这是漂亮的图片显示了7月的使用率(法文)。 剧透:可悲的是,php4的使用率仍然超过35%。

here's a pretty pic showing july usage rates (text in french). spoiler: php4 still has over a 35% usage rate sadly.

这篇关于为什么不在PHP中使用“保护”或“私有”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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