我试图说明key子的配送工作如何,以及我如何用自己的物品/方法开展工作。
I ve been looking at this lib, it does exactly what I want to do myself: https://github.com/antecedent/patchwork
With it you can redefine a method from an object. It uses the monkey patch technique for that. But I couldn t really figure out what exactly is going on by looking at the source.
我有以下目标:
//file: MyClass.php
namespace MyClass;
class MyClass {
public function say()
{
echo Hi ;
}
}
我这样说:
Monkeypatch
eplace( MyClass , say , function() {
echo Hello ;
});
$obj = new MyClass();
$obj->say(); // Prints: Hello
但i m不能确定如何规范实际派遣部分。 我知道这方面的名称空间很重要。 但是,这究竟如何让我拿出某种方法? 我是否还需要在某个地方(如果是,如何)使用电子数据?
I couldn t really find any good examples about this matter, except: http://till.klampaeckel.de/blog/archives/105-Monkey-patching-in-PHP.html
但我确实看不出我如何能够将这一点适用于我自己的物体/方法。 我希望得到很好的解释或榜样。