php - Return same array (zval) as passed in to a function -
i tried create new function in extension takes array
parameter adds entry that same instance of array , returns instance again.
so code far:
php_function(make_array) { // array_init(return_value); // tried transform default null array if (zend_parse_parameters(zend_num_args() tsrmls_cc, "a", &return_value) == failure) { return_false; } add_assoc_long(return_value, "answer", 42); return; }
but null
return value or if uncomment array_init(return_value);
return_value
empty array.
so why behavior? , did understand wrong?
using return_value
directly part of zpp argument typically not done (actually, never); it's commonly done introducing regular zval *
container , return_zval or retval_zval macro used:
php_function(make_array) { zval *arr; if (zend_parse_parameters(zend_num_args() tsrmls_cc, "a", &arr) == failure) { return; } add_assoc_long(arr, "answer", 42); return_zval(arr, 0, 0); }
Comments
Post a Comment