PHP Conference Japan 2024

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 物件。標頭檔可以使用特殊的 FFI_SCOPE 定義(例如 #define FFI_SCOPE "foo";預設範圍為 "C")來擴充,然後在預載入期間由 FFI::load() 載入。這會導致建立持久繫結,該繫結將透過 FFI::scope() 提供給所有後續請求。請參閱 完整的 PHP/FFI/預載範例以瞭解詳細資訊。

可以將多個 C 標頭檔預載入到同一個範圍中。

類別概要

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__

目錄

新增註解

使用者貢獻的註解

此頁面沒有使用者貢獻的註解。
To Top