如何在PHP中重新加载文件?

时间:2016-02-05 20:13:42

标签: php oop

我包含一个File,它在PHP应用程序中用作插件,以便稍后使用ReflectionClass在其中实例化该类。现在,我想在运行时重新加载整个文件,这样我就可以在程序运行时更新代码。我有什么方法可以做到这一点吗?

这是我的一些代码:

$info = new \SplFileInfo("plugins/".$name."/".$main);
include("plugins/".$name."/".$main);
$class = new \ReflectionClass($name."\\".$info->getBasename(".php")); //Taking care of using the correct namespace
$this->class = $class->newInstanceWithoutConstructor();

运行完全相同的代码两次会导致程序崩溃。

编辑:我的插件架构包含一个PluginManager,它应该加载和卸载插件。卸货工作正常。还有一个EventManager,插件使用它来订阅我的程序或其他插件可以触发的特定事件。卸载插件后,插件本身的对象永远不会被任何东西再次使用。

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

对于PHP应用程序似乎不太好。我不确定,但可能是here is the answer on your questionhere is the link on RunKit doc(在评论中找到)

相关问题