Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未实现php和FFI返回结构/联合_Php_C_Ffi_Php Ffi - Fatal编程技术网

未实现php和FFI返回结构/联合

未实现php和FFI返回结构/联合,php,c,ffi,php-ffi,Php,C,Ffi,Php Ffi,我想将rust库绑定到php。 我有一个.h文件,其中包含一些函数和结构声明: typedef struct { const char* content; //char content; uint32_t len; } tc_string_t; typedef struct { tc_string_t result_json; tc_string_t error_json; } tc_response_t; typedef struct { } t

我想将rust库绑定到php。 我有一个.h文件,其中包含一些函数和结构声明:

typedef struct {
    const char* content;
    //char content;
    uint32_t len;
} tc_string_t;

typedef struct  {
    tc_string_t result_json;
    tc_string_t error_json;
} tc_response_t;

typedef struct  {
} tc_response_handle_t;

enum tc_response_flags_t {
    tc_response_finished = 1,
};

typedef void (*tc_on_response_t)(
    int32_t request_id,
    tc_string_t result_json,
    tc_string_t error_json,
    int32_t flags);

void tc_json_request_async(
    uint32_t context,
    tc_string_t method,
    tc_string_t params_json,
    int32_t request_id,
    tc_on_response_t on_result);

tc_response_handle_t* tc_json_request(
    uint32_t context,
    tc_string_t method,
    tc_string_t params_json);

tc_response_t tc_read_json_response(const tc_response_handle_t* handle);
void tc_destroy_json_response(const tc_response_handle_t* handle);
当我从PHP调用时:

$ffi->tc_read_json_response($handle);
我得到了一个错误:

FFI return struct/union is not implemented 

如何实现返回?

我认为PHP还不支持将嵌套结构或联合映射到
FFI\CData
。基本上不可能调用将返回这些类型数据的C API

您可以从这里的PHPSRC中看到:PHP结构中唯一受支持的属性类型本质上是标量或指针。此时会在此处触发您看到的错误:


我认为唯一的选择是编写自己的C包装器,提供返回更简单数据类型的函数。

我认为PHP还不支持将嵌套结构或联合映射到
FFI\CData
。基本上不可能调用将返回这些类型数据的C API

您可以从这里的PHPSRC中看到:PHP结构中唯一受支持的属性类型本质上是标量或指针。此时会在此处触发您看到的错误:

我认为唯一的选择是编写自己的C包装器,它提供返回更简单数据类型的函数