mirror of
https://github.com/php/php-src.git
synced 2024-09-22 18:37:25 +00:00
6738241aec
Scalar FFI values now should be accessed through special "cdata" property. $x = FFI::new("int"); $x = 42; should be changed into $x = FFI::new("int"); $x->cdata = 42;
29 lines
487 B
PHP
29 lines
487 B
PHP
--TEST--
|
|
FFI 036: Type memory management
|
|
--SKIPIF--
|
|
<?php require_once('skipif.inc'); ?>
|
|
--INI--
|
|
ffi.enable=1
|
|
--FILE--
|
|
<?php
|
|
$type = FFI::type("int*");
|
|
|
|
function foo($ptr) {
|
|
global $type;
|
|
//$buf = FFI::new("int*[1]"); /* this loses type and crash */
|
|
$buf = FFI::new(FFI::arrayType($type, [1]));
|
|
$buf[0] = $ptr;
|
|
//...
|
|
return $buf[0];
|
|
}
|
|
|
|
$int = FFI::new("int");
|
|
$int->cdata = 42;
|
|
var_dump(foo(FFI::addr($int)));
|
|
?>
|
|
--EXPECTF--
|
|
object(FFI\CData:int32_t*)#%d (1) {
|
|
[0]=>
|
|
int(42)
|
|
}
|