PHP扩展函数array_init抛出';return_value未声明';


PHP extension function array_init throws 'return_value is undeclared'

这是我第一次尝试创建PHP扩展。我需要一个返回assoc数组的函数。因此,出于测试原因,我创建了一个小函数:

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);
}

但每次我试图编译它时,编译器告诉我:

/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.)

我做错了什么?在我看到的每个例子中,数组变量都没有声明。

查看PHP_FUNCTION()宏的定义。它声明了参数return_value而不是return_array。这就是为什么后者没有被宣布。

错误非常明显。在使用变量return_array之前,您必须声明它。