tags:

views:

252

answers:

1

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(){ 

}
+7  A: 

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

Mez
Unfortunately neither of these solutions are currently possible in my situation.
clops
Do you use PHP 5.3? This would offer a solution.
powtac
The application cannot be porter to PHP 5.3 in its current state. It is more than 250 Mb of code ;)
clops