Main interface to C code and data

(PHP 7 >= 7.4.0, PHP 8)

Introduction

Objects of this class are created by the factory methods FFI::cdef(), FFI::load() or FFI::scope(). Defined C variables are made available as properties of the FFI instance, and defined C functions are made available as methods of the FFI instance. Declared C types can be used to create new C data structures using FFI::new() and FFI::type().

FFI definition parsing and shared library loading may take significant time. It is not useful to do it on each HTTP request in a Web environment. However, it is possible to preload FFI definitions and libraries at PHP startup, and to instantiate FFI objects when necessary. Header files may be extended with special FFI_SCOPE defines (e.g. #define FFI_SCOPE "foo"; the default scope is "C") and then loaded by FFI::load() during preloading. This leads to the creation of a persistent binding, that will be available to all the following requests through FFI::scope(). Refer to the complete PHP/FFI/preloading example for details.

It is possible to preload more than one C header file into the same scope.

Class synopsis

finalclassFFI {
publicstaticaddr(FFI\CData&$ptr): FFI\CData
publicstaticalignof(FFI\CData|FFI\CType&$ptr): int
publicstaticarrayType(FFI\CType$type, array$dimensions): FFI\CType
publicstaticcdef(string$code = "", ?string$lib = null): FFI
publicstaticfree(FFI\CData&$ptr): void
publicstaticisNull(FFI\CData&$ptr): bool
publicstaticload(string$filename): ?FFI
publicstaticmemcmp(string|FFI\CData&$ptr1, string|FFI\CData&$ptr2, int$size): int
publicstaticmemcpy(FFI\CData&$to, FFI\CData|string&$from, int$size): void
publicstaticmemset(FFI\CData&$ptr, int$value, int$size): void
publicnew(FFI\CType|string$type, bool$owned = true, bool$persistent = false): ?FFI\CData
publicstaticscope(string$name): FFI
publicstaticsizeof(FFI\CData|FFI\CType&$ptr): int
publicstaticstring(FFI\CData&$ptr, ?int$size = null): string
publictype(string$type): ?FFI\CType
publicstatictypeof(FFI\CData&$ptr): FFI\CType
}

Predefined Constants

FFI::__BIGGEST_ALIGNMENT__

Table of Contents

To Top