PHP朋友/软件包可见性 [英] PHP friend/package visibility

查看:79
本文介绍了PHP朋友/软件包可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以像在Java中包"可见性或在C ++中至少是朋友"可见性一样,来限制PHP中的可见性?维护大型OOP项目并且不让任何人使用任何代码部分的最佳实践是什么?

Is there any way to limit the visibility in PHP in the same way as "package" visibility works in Java or at least "friend" visibility in C++? What's the best practice to maintain large OOP project and not to let anyone use any part of code?

我尽我所能使用私有和受保护的可见性,但有时还不够.我知道此请求: https://bugs.php.net/bug.php?id = 55331 .在PHP中实现这种东西有什么进展吗?是否有任何变通办法来保护您的代码(方法,类变量)以防止从任何地方访问?

I use private and protected visibility as much as I can but sometimes it's not enough. I know about this request: https://bugs.php.net/bug.php?id=55331. Is there any progress in implementing such thing to PHP? Is there any workaround to protect your code (methods, class variables) from being accessed from anywhere?

推荐答案

此处:

不.您可以在声明名称空间后设置变量,但是变量 将始终存在于全球范围内.他们永远不会被束缚 命名空间.您可以从没有名字的情况下推断出这一点 中的分辨率说明 http://www.php.net/manual/en/language. namespaces.faq.php

No. You can set a variable after declaring a namespace, but variables will always exist in the global scope. They are never bound to namespaces. You can deduce that from the absence of any name resolution descriptions in http://www.php.net/manual/en/language.namespaces.faq.php

这篇关于PHP朋友/软件包可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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