PHP 8.5.0 Released!

FFI::cdef

(PHP 7 >= 7.4.0, PHP 8)

FFI::cdef新しい FFI オブジェクトを作成する

説明

public static FFI::cdef(string $code = "", ?string $lib = null): FFI

新しい FFI オブジェクトを作成します。

パラメータ

code

通常の C 言語の宣言 (型、構造体、関数、変数など) を含む文字列。 実際には、この文字列は C のヘッダーファイルからコピーペーストしてきたものかもしれません。

注意:

C のプリプロセッサーディレクティブはサポートされていません。 例えば、#include#define、プリプロセッサーマクロは動作しません。

lib

共有ライブラリの名前。 ここで指定したライブラリが読み込まれ、与えた定義とリンクされます。

注意:

lib を省略したり null を渡したりすると、 RTLD_DEFAULT をサポートしているプラットフォームでは、 通常のグローバルスコープから code で宣言されているシンボルを探索しようとします。 そうでないシステムでは、シンボルの解決に失敗します。

戻り値

新しく作成された FFI オブジェクトを返します。

変更履歴

バージョン 説明
8.3.0 void を返す C の関数が、FFI\CType::TYPE_VOID ではなく PHP の null を返すようになりました。
8.0.0 lib は、nullable になりました。
add a note

User Contributed Notes 1 note

up
0
derrekbertrand at gmail dot com
5 years ago
You'll probably want to add a C header file, but as of the current version preprocessor directives do not work... so what do? On systems with GCC run the file through this command:

cpp -P /usr/include/unprocessedheader.h -o myprettyheader.h

Note that because preprocessing is not suppored in FFI, C/C++ macros are not supported either. You'll probably still have to write a small wrapper in C unless your library has an exceedingly simple public API.
To Top