Web lists-archives.com

[PHP] 7.1 extension writing, output parameter remains unchanged




Hello,
I'm porting our extension from php5.6 to php7.1 x64 Windows, Visual Studio 2015. I'd like to write an extension function that has one input / output parameter type of long. But the parameter value changed in extension is not changed in php. What I'm doing wrong?
The php code is:

$a = 3;
$r = hello_square($a);
var_export($a); echo "\n"; //value of $a still remains 3, should be 9.

The c code is:

PHP_FUNCTION(hello_square)
{
  long a = 0;
  zval *b;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &b) == FAILURE) {
    return;
  }

  a = Z_LVAL_P(b);
  ZVAL_LONG(b, a*a);

  RETURN_BOOL(1);
}

----

I also implemented hello_square this way
PHP_FUNCTION(hello_square)
{
  zend_long b;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &b) == FAILURE) {
    return;
  }

  b = b * b;
  RETURN_BOOL(1);
}

And the value of $a remains unchanged.

Jan.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php