1

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.

1
  • For a start you never declared return_array as the error saying, should it not be array_init(testing_array)? Commented Aug 18, 2013 at 15:51

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

The error is quite clear. You have to declare the variable return_array before use it.

1 Comment

I know that I need to declare it, but in every tutorial, in every example I saw, it never declared. You can see it here github.com/php/php-src/blob/master/ext/filter/filter.c#L889 - this is a code of filter_list() -function from the standart php extension "filter".

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.