CakeFest 2024: The Official CakePHP Conference

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 {
/* 常量 */
public const int __BIGGEST_ALIGNMENT__;
/* 方法 */
public static addr(FFI\CData &$ptr): FFI\CData
public static alignof(FFI\CData|FFI\CType &$ptr): int
public static arrayType(FFI\CType $type, array $dimensions): FFI\CType
public static cdef(string $code = "", ?string $lib = null): FFI
public static free(FFI\CData &$ptr): void
public static isNull(FFI\CData &$ptr): bool
public static load(string $filename): ?FFI
public static memcmp(string|FFI\CData &$ptr1, string|FFI\CData &$ptr2, int $size): int
public static memcpy(FFI\CData &$to, FFI\CData|string &$from, int $size): void
public static memset(FFI\CData &$ptr, int $value, int $size): void
public new(FFI\CType|string $type, bool $owned = true, bool $persistent = false): ?FFI\CData
public static scope(string $name): FFI
public static sizeof(FFI\CData|FFI\CType &$ptr): int
public static string(FFI\CData &$ptr, ?int $size = null): string
public type(string $type): ?FFI\CType
public static typeof(FFI\CData &$ptr): FFI\CType
}

预定义常量

FFI::__BIGGEST_ALIGNMENT__

目录

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top