使用反射在运行时更改PHP类和方法的内容


Change the content of PHP classes and methods at runtime, with Reflection?

这只是为了好玩,请不要尖叫

我想在运行时重写类方法的内容(我的意思是,不修改文件,只有替换/编辑内存中的代码),这是可能的吗?

使用反射,还是其他什么?

请不要关闭这个问题,我正在寻找另一个答案,而不是runkit

为什么不简单地创建一个新类,从你想要修改和覆盖它的方法继承?

<?php
class MySimpleXML extends SimpleXMLElement {
    public function themethodiwanttooverwrite() {
        //...
    }
}
?>