加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

为什么PHP允许从其他实例调用私有方法?

发布时间:2020-05-25 09:00:30 所属栏目:PHP 来源:互联网
导读:只要它们来自同一个类的实例, PHP就会调用私有方法. 这是the PHP docs解释的方式: Objects of the same type will have access to each others private and protected members even though they are not the same instances. This is because the

只要它们来自同一个类的实例,PHP就会调用私有方法.

这是the PHP docs解释的方式:

Objects of the same type will have access to each others private and protected members even though they are not the same instances. This is because the implementation specific details are already known when inside those objects.

这不会破坏封装吗?具体实现细节的事实如何证明它是正确的?

附:还有其他(面向对象的)语言吗?

对于大多数语言都是如此,在java中你也可以这样做,这是因为对象来自同一个实例,它“知道”相同实例具有的所有属性

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读