[php-src] Issue #7866: Ability to pick PHP value by reference in FFI.

From: Date: Sat, 15 Jan 2022 22:27:49 +0000
Subject: [php-src] Issue #7866: Ability to pick PHP value by reference in FFI.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-239028@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/7866 Comment Author: userqq @cmb69 @dstogov > Hmm, you can pass a PHP string to a C char * without further ado (see > https://www.php.net/manual/en/ffi.examples-basic.php). Wouldn't > that work for you? If there is a possibility to pass PHP string to C function and modify string value inside C function by reference maybe then FFI::cast() could be allowed for strings in such way: ```php $string = 'aaaa'; $chars = FFI::cast('char[4]', $string); var_dump($chars); /* object(FFI\CData:char[4])#1 (4) { [0]=> string(1) "a" [1]=> string(1) "a" [2]=> string(1) "a" [3]=> string(1) "a" } */ $chars[2] = 'b'; var_dump($string); /* string(4) "aaba" */ $string = 'a'; FFI::cast('char[4]', $string); // FFI\Exception: attempt to cast to larger type FFI::cast('char[4]', 'aaaa'); // Error: FFI::cast(): Argument #2 ($ptr) cannot be passed by reference

« previous php.bugs (#239028) next »