开发者

Undeclare a class in PHP [closed]

开发者 https://www.devze.com 2022-12-08 19:56 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago.

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 identicall开发者_开发百科y 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

0

精彩评论

暂无评论...
验证码 换一张
取 消