I implemented dynamic loading of plugins in the following way:
function processPlugin( $plgFile, $db ) {
require_once( $plgFile );
$plgin = new PlginImpl();
$plgin->setDb($db);
$ret = $plgin->process();
return $ret;
}
Each plugin defines a class named PlginImpl
, which works fine. But it should be possible to call further plugins specified within within the return value of process()
. That would call the same method specified above, but fails with:
Fatal error: Cannot redeclare class PlginImpl in ..
Please note that each plugin is a class, i.e.:
class PlginImpl extends Plugin implements PluginInterface
Plugin
offer some useful functions while PluginInterface
defines i.e. process()
.
I assume that the fact that all plugins are named PlginImpl causes the problem, hence my question: is there a way to unload a class (PlginImpl
) after loading it with require_once
? Or is there an entirely different approach I should follow?
EDIT I tried without succeeding the following things:
- unset
$plgin
afterprocess()
- calling
__destruct()
- it doesn't work neither withinprocessPlugin()
nor within theprocess
method
Many, many thanks!