1

I get a tricky problem when i am trying to create a php extension with c, with an array returned. I do as some tutorials said, but i need to return an array. array_init(return_array) in all examples is said to initialize an returning-array, but i find nowhere the return_array is declared. So, i got error: error C2065: 'return_array' : undeclared identifier, however, if i add :

zval * return_array ;

But it throws your app cannot read address 000000f why?

Can you give me a detailed extension example containing array-returning....thanx millions times

1
  • look at nearly any function that returns an array. can you post the full code?
    – mfonda
    Jan 8, 2011 at 4:33

2 Answers 2

0

If you want to return the array, just initialize return_value:

array_init(return_value);

return_value is a zval*, declared by the PHP_FUNCTION() macro.

0

The following code gives an example of returning array:

array_init(return_value);
add_index_long(rturn_value,0,10);
add_index_stringl(return_value,1,"test",1);
zval * record;
MAKE_STD_ZVAL(record);
array_init(record);
add_assoc_long(record,"key",1);
add_index_zval(return_value,2,record);
return;

This will return the following results in php namespace, which cover most php extension returning scenarios:

array(
    10,
    "test",
    array(
        "key" => 1
    )
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.