1

我第一次尝试创建 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.)

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

4

2 回答 2

1

查看PHP_FUNCTION()宏的定义。它声明论点return_value not return_array。这就是为什么后者没有被声明的原因。

于 2013-08-29T23:51:25.690 回答
0

错误很明显。return_array您必须在使用之前声明变量。

于 2013-08-18T15:53:11.257 回答