C 代码和数据的主接口
(PHP 7 >= 7.4.0, PHP 8)
简介
通过工厂方法 FFI::cdef()、FFI::load() 或 FFI::scope() 创建该类的对象。定义的 C 变量作为有效的 FFI 实例属性,定义的 C 函数作为有效的 FFI 实例方法。声明的 C 类型可以用于 FFI::new() 和 FFI::type() 创建新的 C 数据结构。
FFI 定义解析和共享库加载可能需要较长时间。在 Web 环境中,每个 HTTP 请求都进行这些操作是没有意义的。然而,在 PHP 启动时预加载
FFI 定义和库,并在需要时实例化 FFI 对象是可能的。header 文件可以使用特殊的 FFI_SCOPE
定义进行扩展(例如
#define FFI_SCOPE "foo"
),然后在预加载期间由 FFI::load() 加载。这将创建持久绑定,将通过
FFI::scope() 在所有后续请求中可用。有关详细信息,请参阅完整的 PHP/FFI/preloading 示例。
可以将多个 C header 文件预加载到同一作用域中。
类摘要
final
class FFI
{
/* 常量 */
/* 方法 */
}目录
- FFI::addr — Creates an unmanaged pointer to C data
- FFI::alignof — Gets the alignment
- FFI::arrayType — Dynamically constructs a new C array type
- FFI::cast — Performs a C type cast
- FFI::cdef — Creates a new FFI object
- FFI::free — Releases an unmanaged data structure
- FFI::isNull — Checks whether a FFI\CData is a null pointer
- FFI::load — Loads C declarations from a C header file
- FFI::memcmp — Compares memory areas
- FFI::memcpy — Copies one memory area to another
- FFI::memset — Fills a memory area
- FFI::new — Creates a C data structure
- FFI::scope — Instantiates an FFI object with C declarations parsed during preloading
- FFI::sizeof — Gets the size of C data or types
- FFI::string — Creates a PHP string from a memory area
- FFI::type — Creates an FFI\CType object from a C declaration
- FFI::typeof — Gets the FFI\CType of FFI\CData
+添加备注
用户贡献的备注
此页面尚无用户贡献的备注。