Hi,
I'm calling the function php_pcre_replace() in my extension:
http://lxr.php.net/xref/PHP_5_4/ext/pcre/php_pcre.c#952
I would like to use a callback for the replace_val, but this will be
supplied by my extension. I'm wondering what the recommended way of
creating the replace_val zval callback would be in the extension.
Thank you for your patience and help.
Adam
Same as you would in PHP code. Make an IS_STRING pointing at a global
function, or IS_ARRAY pointing at a class method, or an IS_OBJECT
supporting __invoke(). If you're asking how you can call a C function
directly via this callback: You can't. You can can, however, make an
internal method to use as a callback, just bear in mind it'll be callable
by userspace as well.
-Sara
On Sat, Jul 14, 2012 at 2:00 PM, Adam Jon Richardson adamjonr@gmail.comwrote:
Hi,
I'm calling the function php_pcre_replace() in my extension:
http://lxr.php.net/xref/PHP_5_4/ext/pcre/php_pcre.c#952I would like to use a callback for the replace_val, but this will be
supplied by my extension. I'm wondering what the recommended way of
creating the replace_val zval callback would be in the extension.Thank you for your patience and help.
Adam
Same as you would in PHP code. Make an IS_STRING pointing at a global
function, or IS_ARRAY pointing at a class method, or an IS_OBJECT supporting
__invoke(). If you're asking how you can call a C function directly via
this callback: You can't. You can can, however, make an internal method to
use as a callback, just bear in mind it'll be callable by userspace as well.
Thank you very much for your explanation, Sara. I got my code working,
but I must confess I wasn't confident it was the preferred approach
and I wanted to make sure I was learning the recommended approach.
I've taken to heart the many examples in your book where you bring up
the most obvious/likely method to do something in the extension world
only to find out it's not the preferred/correct approach.
Thank you very much for the clarification.
Adam
P.S. - Your book has aged exceedingly well, and it's a great reference
for people like me trying to find their way around the internals :)
Nice writing style!