Question

My level of experience: very comfortable with C, novice to PHP, new to and very frustrated with Zend Engine (no documentation?)

I'm trying to write my first PHP extension, and I'm wondering if the following is even possible.

PHP code illustrating my goal:

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();

Also, I'm aware I could just rewrite foo to call a function exposed by the extension, but that's not interesting to me. I just want to know if the above example (where the PHP class is not aware of and does not cooperate with the extension) is possible.

Était-ce utile?

La solution

The runkit extension does this kind of thing: http://www.php.net/manual/en/function.runkit-method-redefine.php

It's available for download at http://pecl.php.net/package/runkit but there are much recent changes in git://git.php.net/pecl/php/runkit.git

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top