C Data Handles
(PHP 7 >= 7.4.0)
FFI\CData objects can be used in a number of ways as a regular PHP data:
C data of scalar types can be read and assigned via the $cdata property, e.g.
$x = FFI::new('int'); $x->cdata = 42;
C struct and union fields can be accessed as regular PHP object property, e.g.
C array elements can be accessed as regular PHP array elements, e.g.
- C arrays can be iterated using foreach statements.
- C arrays can be used as arguments of count().
C pointers can be dereferenced as arrays, e.g.
C pointers can be compared using regualar comparison operators (
C pointers can be incremented and decremented using regular
$cdata += 5
C pointers can be subtracted from another using regular
C pointers to functions can be called as a regular PHP closure, e.g.
Any C data can be duplicated using the clone
$cdata2 = clone $cdata;
- Any C data can be visualized using var_dump(), print_r(), etc.