Main interface to C code and data

(PHP 7 >= 7.4.0, PHP 8)

EinfΓΌhrung

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.

Klassenbeschreibung

final class FFI {
/* Konstanten */
public const int __BIGGEST_ALIGNMENT__;
/* Methoden */
public static function addr(FFI\CData &$ptr): FFI\CData
public static function alignof(FFI\CData|FFI\CType &$ptr): int
public static function arrayType(FFI\CType $type, array $dimensions): FFI\CType
public function cast(FFI\CType|string $type, FFI\CData|int|float|bool|null &$ptr): ?FFI\CData
public static function cdef(string $code = "", ?string $lib = null): FFI
public static function free(FFI\CData &$ptr): void
public static function isNull(FFI\CData &$ptr): bool
public static function load(string $filename): ?FFI
public static function memcmp(string|FFI\CData &$ptr1, string|FFI\CData &$ptr2, int $size): int
public static function memcpy(FFI\CData &$to, FFI\CData|string &$from, int $size): void
public static function memset(FFI\CData &$ptr, int $value, int $size): void
public function new(FFI\CType|string $type, bool $owned = true, bool $persistent = false): ?FFI\CData
public static function scope(string $name): FFI
public static function sizeof(FFI\CData|FFI\CType &$ptr): int
public static function string(FFI\CData &$ptr, ?int $size = null): string
public function type(string $type): ?FFI\CType
public static function typeof(FFI\CData &$ptr): FFI\CType
}

Vordefinierte Konstanten

FFI::__BIGGEST_ALIGNMENT__

Inhaltsverzeichnis

  • 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
οΌ‹add a note

User Contributed Notes

There are no user contributed notes for this page.