Unload dynamic class in PHP

Since you can't unload a class after you've loaded it, the only option you have is to rename each plugin.

PluginX, PluginY, etc., but it shouldn't matter as you can just force them to use the plugin interface as you showed.

To load a specific plugin, you could simply have something like solomongaby suggests, but instead of a filename, you pass it the name of the plugin.. something like this:

function loadPlugin($pluginName) {
    require_once $pluginName . '.php';

    $plugin = new $pluginName;
    //do whatever with $plugin
}

Another option, though I don't recommend it, is to use runkit_import.

Tags:

Php