For the first time I'm trying to create PHP extenstion. I need a function that will return an assoc array. So for the test reasons I created a small function:
PHP_FUNCTION(testing_array) {
char *firstVal = NULL;
char *secondVal= NULL;
int argc = ZEND_NUM_ARGS();
int firstVal_len;
int secondVal_len;
if (zend_parse_parameters(argc TSRMLS_CC, "ss", &firstVal, &firstVal_len, &secondVal, &secondVal_len) == FAILURE)
return;
array_init(return_array);
}
But everytime I'm tryimg to compile it, compiler tells me:
/root/php/php-src/ext/hello_world/hello_world.c:87: error: return_array undeclared (first use in this function)
/root/php/php-src/ext/hello_world/hello_world.c:87: error: (Each undeclared identifier is reported only once
/root/php/php-src/ext/hello_world/hello_world.c:87: error: for each function it appears in.)
What I'm doing wrong? In every example I saw, array variable isn't declared.
The error is quite clear. You have to declare the variable return_array
before use it.
Look at the definition of the PHP_FUNCTION()
macro. It declares the argument return_value
not return_array
. That's why the latter isn't declared.