简体   繁体   English

用PHP包?

[英]Packages in PHP?

Is it possible to create packages of related classes and have the same protected and private fields which are visible only to classes from within the same package? 是否可以创建相关类的包并具有相同的protectedprivate字段,这些字段仅对同一个包中的类可见?

Basically, the same type of packages as what Java has. 基本上,与Java具有相同类型的包。 Is it possible? 可能吗?

Right now, there is no concept of package. 现在,没有包装的概念。

However, PHP 5.3 is going to introduce namespaces . 但是,PHP 5.3将引入名称空间 I'm not sure about how that will affect visibility between classes. 我不确定这将如何影响课程之间的可见性。

Nope. 不。 PHP has no package or friend-class support. PHP没有包或朋友级支持。

Here are two approaches I've stumbled upon pondering the same issue: 以下是我在探讨同一问题时偶然发现的两种方法:

Simulating Packages in PHP 在PHP中模拟包

PHP Package Management and Autoloading PHP包管理和自动加载

And it looks like there are some more import analogs in the PHP require_once() docs . PHP require_once()文档中看起来有更多的导入类比。 Hope it helps someone going forward. 希望它可以帮助某些人前进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM