{"id":20398919,"url":"https://github.com/chopins/ffi-ext","last_synced_at":"2025-04-12T13:22:07.625Z","repository":{"id":57071119,"uuid":"243086147","full_name":"chopins/ffi-ext","owner":"chopins","description":"php C API","archived":false,"fork":false,"pushed_at":"2020-11-16T09:10:07.000Z","size":63,"stargazers_count":7,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T08:06:01.031Z","etag":null,"topics":["c","ffi","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chopins.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-25T19:37:52.000Z","updated_at":"2024-03-08T20:28:20.000Z","dependencies_parsed_at":"2022-08-24T10:41:06.619Z","dependency_job_id":null,"html_url":"https://github.com/chopins/ffi-ext","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chopins%2Fffi-ext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chopins%2Fffi-ext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chopins%2Fffi-ext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chopins%2Fffi-ext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chopins","download_url":"https://codeload.github.com/chopins/ffi-ext/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571910,"owners_count":21126541,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","ffi","php"],"created_at":"2024-11-15T04:25:13.800Z","updated_at":"2025-04-12T13:22:07.597Z","avatar_url":"https://github.com/chopins.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[中文](#php-ffi-增强功能)\n# php FFI Extend\nCall PHP C API\n\nphp DLL(php7.dll,php7ts.dll) find order, if file exists loading:\n  * like unix os, Usually does not require additional loading\n  * in windows, find order:\n    1. if undefine constant `PHP_DLL_FILE_PATH`, will find environment variable `PHP_DLL_FILE_PATH`\n    2. find user constant `PHP_DLL_FILE_PATH`\n    3. find directory of predefined constant `PHP_BINARY` (physical location, not `PHP_BINDIR`)\n    4. find php parent directory of ext directory (physical location, not `PHP_EXTENSION_DIR`)\n    5. find `PHP_BINDIR` directory\n    6. find `PHP_LIBDIR` directory\n\n**Note: constant `PHP_DLL_FILE_PATH` work for like unix OS**\n\n**constant `PHP_FFI_EXTEND_APPEND_CDEF` is append cdef code\n\n# Reference\n\n### class `Toknot\\FFIExtend` of methods\n|                方法                    |                            描述                          |\n|---------------------------------------|---------------------------------------------------------|\n| 1. `__construct()`                    |                                                         |\n| 2. `phpffi() : ffi`                   | get ffi                                                 |\n| 3. `emalloc($size) : CData`           | emalloc memory, and set 0                               |\n| 4. `castSameType(FFI $ffi, \u0026$arg)`    | cast to same type                                       |\n| 5. `zvalValue(FFI\\CData $zval) : CData` | get value of php C zval struct                        |\n| 6. `zval($var): CData`                | get C zval(CData) from php variable($var, php string,int ...) |\n| 7. `ZSTR_VAL(CData $str) : CData`     | php C `ZSTR_VAL` macro                                  |\n| 8. `ZSTR_LEN(CData $str) : int`       | php C `ZSTR_LEN` macro                                  |\n| 9. `getCTypeName(CType $type):string` | get C type name                                         |\n| 10. `Z_TYPE(CData $type) : int`       | php C `Z_TYPE` macro                                    |\n| 11. `getZStr(CData $str) : string`    | get string from string zval                             |\n| 12. `Z_OBJ_P(CData $obj)`             | php C `Z_OBJ_P` macro, `$obj` must be pointer           |\n| 13. `isNull($v) : bool`               | check `$v` whether is `NULL` or C `NULL`                |\n| 14. `zend_hash_find_ptr(CData $zendArrayPtr, CData $name, string $type): CData` | find a value from php C hash array, and cast to `$type`                                                                   |\n| 15. `zend_hash_num_elements(CData $array) : int` | get number of php C HashTable                |\n| 16. `hasCFunc(FFI $ffi, string $name) : bool` | check given `$name` of function whether in given FFI `$ffi`                                                                                            |\n| 17. `hasCVariable(FFI $ffi, string $name) : bool` | check given `$name` of variable  whether in given FFI `$ffi`                                                                                            |\n| 18. `hasCType(FFI $ffi, string $name) : bool` | check given `$name` of c type  whether in given FFI `$ffi`                                                                                            |\n| 19. `Z_PTR_P(CData $zval) : CData`    | php C `Z_PTR_P` macro, `$zval` must be pointer          |\n| 20. `ZEND_FFI_TYPE(CData $t) : CData` | php FFI of `ZEND_FFI_TYPE` macro                        |\n| 21. `castAllSameType(FFI $ffi, array \u0026$args)` |  cast array of args to same type                |\n| 22. `iteratorZendArray(CData $hashTable, callable $callable)` | iterator a zend HashTable, `$hashTable` must be pointer, the `$callable` smailer to `function callback($key, $value)`                     |\n| 23. `argsPtr(int $argc, array $argv): CData` | php `$argv` array to C `char**`                  |\n| 24. `strToCharPtr(string $string): CData`  |  php string to C `char*`                           |\n| 25. `strToCharArr(string $string): CData` | php string to C `char[]`                            |\n| 26. `is64(): bool`                    | check os whether is 64bit (whether is LP64)             |\n\n\n### class `Toknot\\ReflectionCFunction` of methods\n|                方法                    |                            描述                         |\n|---------------------------------------|---------------------------------------------------------|\n| 1. `__construct(FFI $ffi, string $name)` | Reflection FFI `$ffi` of C function `$name`          |\n| 2. `getName()`                        | get function name                                       |\n| 3. `getClosure() : Closure`           |                                                         |\n| 4. `isVariadic() : bool`              |                                                         |\n| 5. `getNumberOfParameters() : int`    | get number of parameters                                |\n| 6. `getReturnType(): string`          | get return type                                         |\n| 7. `getParameters(): array`           | get parameters type list                                |\n\n\n# PHP FFI 增强功能\nPHP DDL(php7.dll,php7ts.dll，动态库)查找顺序，如果文件存在：\n  * 对于类UNIX系统，通常是不需要指定加载。通常当PHP以其他程序的模块方式安装时需要指定\n  * 对于windows\n    1. 如果未定义常量`PHP_DLL_FILE_PATH`，将会使用环境变量 `PHP_DLL_FILE_PATH`定义的路径\n    2. 根据常量 `PHP_DLL_FILE_PATH` 指定路径查找,（实际位置，非`PHP_BINDIR`)\n    3. 根据PHP预定义常量`PHP_BINARY` 指定的路径查找 (实际位置，非`PHP_EXTENSION_DIR`)\n    4. 在PHP扩展所在文件夹的上一层文件夹下查找\n    5. 在`PHP_BINDIR`目录查找\n    6. 在`PHP_LIBDIR`目录查找\n\n**注意:  常量 `PHP_DLL_FILE_PATH` 在类UNIX系统下依然有效**\n\n# 类方法参考列表\n\n### 类 `Toknot\\FFIExtend` 的方法\n|                方法                    |                            描述                         |\n|---------------------------------------|---------------------------------------------------------|\n| 1. `__construct()`                    |                                                         |\n| 2. `phpffi() : ffi`                   | 获得PHP C 接口的 FFI 类对象                                |\n| 3. `emalloc($size) : CData`           | 分配内存，并设置为0                                        |\n| 4. `castSameType(FFI $ffi, \u0026$arg)`    | 转换任意其他FFI对象的C数据到指定FFI对象的同结构名字的C数据        |\n| 5. `zvalValue(FFI\\CData $zval) : CData` |    get value of php C zval struct                      |\n| 6. `zval($var): CData`                | get C zval(CData) from php variable($var, php string,int ...)|\n| 7. `ZSTR_VAL(CData $str) : CData`     | php C `ZSTR_VAL` macro                                    |\n| 8. `ZSTR_LEN(CData $str) : int`       | php C `ZSTR_LEN` macro                                    |\n| 9. `getCTypeName(CType $type):string`  | 获取指定CType的结构名字                                     |\n| 10. `Z_TYPE(CData $type) : int`       | php C `Z_TYPE` macro                                      |\n| 11. `getZStr(CData $str) : string`    | get string from string zval                               |\n| 12. `Z_OBJ_P(CData $obj)`             | php C `Z_OBJ_P` macro, `$obj` must be pointer             |\n| 13. `isNull($v) : bool`               | 检查 `$v` 是 PHP `NULL` 或 C `NULL`                         |\n| 14. `zend_hash_find_ptr(CData $zendArrayPtr, CData $name, string $type): CData` | 从 PHP hashTable 中查找指定元数的值，并转换成指定类型   |\n| 15. `zend_hash_num_elements(CData $array) : int` | 获取 php HashTable 元素的个数                      |\n| 16. `hasCFunc(FFI $ffi, string $name) : bool` | 检测指定名字的函数是否存在与指定的FFI对象中               |\n| 17. `hasCVariable(FFI $ffi, string $name) : bool` | 在FFI对象中，检查指定函数名字是否是可变函数           |\n| 18. `hasCType(FFI $ffi, string $name) : bool` | 在FFI对象中，检查指定的类型名是否存在                     |\n| 19. `Z_PTR_P(CData $zval) : CData`     | php C `Z_PTR_P` macro, `$zval` must be pointer             |\n| 20. `ZEND_FFI_TYPE(CData $t) : CData`  | php FFI of `ZEND_FFI_TYPE` macro                           |\n| 21. `castAllSameType(FFI $ffi, array \u0026$args)` |  批量转换到指定FFI的同名数据结构                         |\n| 22. `iteratorZendArray(CData $hashTable, callable $callable)` | 迭代一个Zend HashTable,`$hashTable`必须数指针，`$callable`原型必须类似`function callback($key, $value)`     |\n| 23. `argsPtr(int $argc, array $argv): CData`  | 将PHP `$argv` 数组转换成C `char**`                    |\n| 24. `strToCharPtr(string $string): CData`  |  将 PHP 字符串转换成C `char*`                            |\n| 25. `strToCharArr(string $string): CData`  | 将 PHP 字符串转换成C `char[]`                            |\n| 26. `is64(): bool`                     | 检查系统是否是64位(是否是64位数据模型)                          |\n\n### 类 `Toknot\\ReflectionCFunction` 的方法\n|                方法                    |                            描述                         |\n|---------------------------------------|---------------------------------------------------------|\n| 1. `__construct(FFI $ffi, string $name)` | 反射指定 FFI `$ffi` 的 C 函数 `$name`                   |\n| 2. `getName()`                        | 获取函数名                                                |\n| 3. `getClosure() : Closure`           | 返回函数的闭包                                            |\n| 4. `isVariadic() : bool`              | 是否是可变函数                                             |\n| 5. `getNumberOfParameters() : int`    | 获取参数个数                                              |\n| 6. `getReturnType(): string`          | 获取返回类型                                               |\n| 7. `getParameters(): array`           | 获取参数类型列表                                             |","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchopins%2Fffi-ext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchopins%2Fffi-ext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchopins%2Fffi-ext/lists"}