I’ve stumbled upon an interesting case while developing an extension for PHP. In the extension code I have:
PHP_FUNCTION(foo)
{
....
php_debug_zval_dump(return_value, 1);
}
In the PHP code:
$v = foo();
debug_zval_dump($v);
When running the above, I get:
string(19) "Mouse configuration" refcount(1)
NULL refcount(2)
What can be the reason that the value isn’t passed properly from the extension?
Thanks!
It’s not that strange.
For instance, if you did
return_value = some_string_zval;you would be changing only the local variable.php_debug_zval_dumpwould work, but it would have no effect outside the function. You have to actively copy the zval, e.g. with:The only case you could return from an internal function merely copying a pointer instead of copying data was if that function returned by reference. In that case, you’re given a
zval**.