Skip to content
Advertisement

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:

JavaScript

I’m getting an exception: FFIException: Incompatible types when assigning to type 'char*' from PHP 'string'

My question is: How to set the char *name of a struct?

My dirty way was to make an array of chars, str_split the string and set the keys of the char array to the splitted characters.

JavaScript

but with this approach I have an issue with Null Terminated Strings and don’t know how to solve it as well.

P.S.: I’ve got just basic C knowledge.

Advertisement

Answer

The solution is:

JavaScript

Solution provided by Dmitry Stogov on https://github.com/dstogov/php-ffi/issues/40

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