I am currently rewriting our PHP extension from PHP5 to PHP7. To call PHP methods from our C/C++ code we use slightly modified zend_call_method
from Zend/zend_interfaces.c (to use more arguments than 2). Now I found out that it does not work with arguments passed by reference,
public function FuncWithRef(array &$changeThis)
if they are changed in the PHP code then zval values in C part are not influenced. In PHP5 the value was overwritten as expected and could be used later in C code.
Previously the zend_fcall_info
struct for function call was filled with params simply by
params[0] = &arg1;
In PHP7 this is changed to
ZVAL_COPY_VALUE(¶ms[0], arg1);
After function is executed (zend_call_function
) both fci.params
and arg1
contain still the original zval values, changes made in PHP code are not available. I tried things like using DUP instead of COPY but with no result. Is there any way how to solve this? I am mainly searching for and comparing code snippets in PHP/ext folder to see how things were rewritten from PHP5 to PHP7 and this seems to be hopefully the last part missing for me.
Two differences between PHP5 and PHP7 approach in zend_call_method:
fci.no_separation = 0;
has to be set. Then fci.params are changed inside zend_call_function and then they have to be manually copied back to zend_call_method input args.