Skip to content
Advertisement

Why i cannot use word, byte on struct in PHP FFI? But char, int, short works?

My code:

public function loadFFI()
{
    FFI::load("C:phptestdummy.h");
}

dummy.h:

struct ffitest
{
    char test1[16];
    byte test2;
};

Error:

PHP Fatal error: Uncaught FFIParserException: Undefined C type “byte” at line 4

Why can I not use word or byte in this struct in PHP FFI? char, int, and short work as expected.

Advertisement

Answer

There is no such thing as a byte data type in standard C. Since char is already defined as a single byte, you should use that instead. If you want values 0-255 instead of -127 to 127, don’t forget to make it an unsigned char.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement