The PHP Foreign Function Interface extension was introduced in PHP 7.4 as a way to load libraries (e.g. SO or DLL files) and then call C functions or access C data structures in pure PHP code. It was based upon similar extensions for Python and Lua. As of PHP 8.0 it is still considered to be an experimental extension.
Questions tagged [php-ffi]
9 questions
5
votes
1 answer
PHP FFI - return array rom Rust function back to PHP
I need to return few values from rust function. Tried to declare function which returns an array
$ffi = FFI::cdef('float get_arr()[2];', './target/release/libphp_rust.dylib');
$array = $ffi->get_arr();
But got an error:
PHP Fatal error: Uncaught…

zoryamba
- 196
- 11
2
votes
1 answer
Can we use PHP FFI to run python scripts?
I have been doing a lot of search engine search for past 7 days on how to do FFI with python but most examples are on using C or Rust and one example on using go lang but I do not see anyone going with Python but it is widely used one.
Can we use…

sarathkm
- 1,306
- 1
- 9
- 11
2
votes
1 answer
Problem loading a library with FFI in PHP 7.4
I'm having trouble using a third party .so library in PHP with the new FFI.
When I run this little piece of code:

Heverton Coneglian de Freitas
- 195
- 2
- 14
2
votes
0 answers
FFI API is restricted
I want to test PHP 7.4 FFI functionality. I have PHP 7.4beta4 installed on Ubuntu 16/Apache 2.4
FFI is enabled in my php.ini with:
ffi.enable = true
Here is my php file:

Audiophile
- 970
- 2
- 8
- 20
1
vote
1 answer
Why i cannot use word, byte on struct in PHP FFI? But char, int, short works?
My code:
public function loadFFI()
{
FFI::load("C:\phptest\dummy.h");
}
dummy.h:
struct ffitest
{
char test1[16];
byte test2;
};
Error:
PHP Fatal error: Uncaught FFI\ParserException: Undefined C type "byte" at line 4
Why can I not…

qwerty1547
- 13
- 3
1
vote
1 answer
php and FFI return struct/union is not implemented
I want to bind rust library to php.
I have .h file with some declarations of functions and structs:
typedef struct {
const char* content;
//char content;
uint32_t len;
} tc_string_t;
typedef struct {
tc_string_t result_json;
…

Николай Кушпела
- 15
- 2
- 4
1
vote
1 answer
php-ffi: Assign char* of a struct
I'm trying to set the value of a char* of a struct. This is a basic example:
$ffi = FFI::cdef('typedef struct
{
const char *name;
} example_t;');
$struct = $ffi->new('example_t');
$struct->name = 'Test';
// FFI\Exception:…

zembrowski
- 21
- 6
0
votes
1 answer
PHP FFI possible on ARMv8?
I can load my library through the FFI on x86_64 but not on AArch64.
FFI::cdef(
/* ... */,
$root . './build/libuplink.so'
);
PHP Fatal error: Uncaught FFI\Exception: Failed loading '/home/linaro/uplink-php/build/libuplink.so' in…

Erik van Velzen
- 6,211
- 3
- 23
- 23
0
votes
1 answer
php-ffi: Return type const char* is a string
Why is the result of const char * a string and char * an object „byte-array“?
A simple example:
$ffi = FFI::cdef(
"const char *strerror(int errnum);",
"libc.so.6"
);
var_dump($ffi->strerror(1));
returns
string(23) "Operation not…

zembrowski
- 21
- 6