取消声明PHP中的类 [英] Undeclare a class in PHP
问题描述
我有一个守护程序在后台处理相当多的MVC逻辑,其中包括它需要的类.但是,有时甚至会在一个循环中包含来自不同模块的两个名称相同的类.理想情况下,如果可能的话,我想在再次包含它之前先取消声明"一个类,但是如果可以的话,我在PHP手册中找不到.
类似这样的东西:
//first foo
class foo(){
}
//undeclare foo
undeclare foo;
//create new foo
class foo(){
}
无法取消声明"一个类.
您可能应该研究PHP的名称间隔,或者使用类似的约定来命名您的类>
Application_Module_Class
所以你会打电话给
$x = new Application_Foo_Bar;
包括Foo模块中的Bar类
这也很适合使用自动加载函数
I have a daemon processing quite a bit of MVC logic in the background that includes the classes it needs on demand. Sometimes, however, it comes to a point where it includes two identically named classes from different modules within one cycle. Ideally, I would like to "undeclare" a class before I include it again, I cannot find in the PHP manual however, if this is possible.
Something like this:
//first foo
class foo(){
}
//undeclare foo
undeclare foo;
//create new foo
class foo(){
}
It is not possible to "undeclare" a class.
You should probably look into PHP's namespacing or, use a convention for naming your classes similar to
Application_Module_Class
so you would be calling
$x = new Application_Foo_Bar;
to include the Bar class from the Foo module
This also lends itself quite well to using autoload functions
这篇关于取消声明PHP中的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!