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

goat
  • 31,486
  • 7
  • 73
  • 96
StevenWang
  • 3,625
  • 4
  • 30
  • 40

2 Answers2

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
    )
)
cedricliang
  • 352
  • 1
  • 7
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.

Arnaud Le Blanc
  • 98,321
  • 23
  • 206
  • 194