问题
I followed the steps mentioned at Passing a variable by reference into a PHP extension for Passing a variable by reference into a PHP extension. This is working fine for PHP 5 but when I try the same in Php7 and its not working. Any suggestions? Here is my code snippet.
ZEND_BEGIN_ARG_INFO(params_ref_arg_arginfo, 0)
ZEND_ARG_INFO(1, a)
ZEND_END_ARG_INFO()
PHP_FUNCTION(sample_byref_compiletime)
{
zval *a;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &a ) == FAILURE)
{
php_printf("Error");
RETURN_NULL();
}
zval_dtor(a);
ZVAL_LONG(a, 40);
}
PHP_FE(sample_byref_compiletime, params_ref_arg_arginfo)
Thank you for the help.
回答1:
Change from "z" to "z/". View details in https://wiki.php.net/phpng-upgrading. Possible type specifiers http://php.net/manual/en/internals2.funcs.php.
Also you can change your code to:
PHP_FUNCTION(sample_byref_compiletime)
{
zval *a;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"z", &a ) == FAILURE)
{
php_printf("Error");
RETURN_NULL();
}
ZVAL_DEREF(a);
SEPARATE_ZVAL_NOREF(a);
zval_dtor(a);
ZVAL_LONG(a, 40);
}
来源:https://stackoverflow.com/questions/36349087/passing-a-variable-by-reference-into-a-php7-extension