php扩展,用C语言编写的处理程序替换php类方法


php extension to replace PHP class method with handler written in C

我的经验水平:C语言非常熟练,PHP新手,Zend Engine新手,非常沮丧(没有文档?)

我正在尝试编写我的第一个PHP扩展,我想知道以下是否可能。

说明我的目标的PHP代码:
class MyClass
{
    public function foo($bar)
    {
        (stuff that runs extremely slowly in PHP)
        return "result";
    }
}
$a = new MyClass();
echo "Watch how slow this is: ", $a->foo();
tell_my_custom_php_extension_to_replace_foo_with_my_reimplementation_of_foo_in_c("MyClass");
echo "Wow, now it's wonderfully fast! See: ", $a->foo();

另外,我知道我可以重写foo来调用扩展所暴露的函数,但这对我来说并不有趣。我只是想知道如果上面的例子(其中PHP类不知道,不与扩展合作)是可能的。

runkit扩展做这样的事情:http://www.php.net/manual/en/function.runkit-method-redefine.php

可以在http://pecl.php.net/package/runkit下载,但是git最近有很多变化://git.php.net/pecl/php/runkit.git