Using FFI infrastructural methods
Learn the methods that provide the necessary infrastructure to execute C functions in PHP 8.
We'll cover the following...
FFI extension infrastructural category methods can be thought of as behind-the-scenes components that support the infrastructure needed for C function binding to work properly. The FFI extension is needed if we wish to access C data structures from within a PHP application directly. Thus, if we need to do the equivalent of a PHP unset()
statement to release memory or a PHP include()
statement to include external program code, the FFI extension infrastructural methods provide the bridge between native C data and PHP.
Summary of FFI Class Infrastructural Methods
FFI Methods | Returns | Notes |
|
| Creates a pointer to C data. |
|
| Performs a C language type cast. |
|
| Releases an FFI pointer. There is no direct equivalent in PHP |
|
| Copies specified bytes from one |
|
| Populates a |
Let’s first have a look at FFI::addr()
, free()
, memset()
, and memcpy()
.
Working with FFI::addr()
, free()
, memset()
, and memcpy()
PHP developers often assign a value to a variable by reference. This allows a change in one variable to be automatically reflected in another. The use of references is especially useful when passing parameters to a function or method where we need to return more than a single value. ...