Passing a variable by reference into a PHP7 extension

邮差的信 提交于 2019-12-11 12:18:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!