1--TEST-- 2FFI 040: Support for scalar types 3--EXTENSIONS-- 4ffi 5--SKIPIF-- 6<?php 7if (pack('S', 0xABCD) !== pack('v', 0xABCD)) { 8 die('skip for little-endian architectures only'); 9} 10?> 11--INI-- 12ffi.enable=1 13--FILE-- 14<?php 15$x = FFI::new("int"); 16$x->cdata = 5; 17var_dump($x); 18var_dump(FFI::typeof($x)); 19var_dump(FFI::cast("int8_t[4]", $x)); 20$p = FFI::addr($x); 21var_dump($p); 22$p[0] += 2; 23var_dump($x); 24var_dump(FFI::sizeof($x)); 25var_dump(FFI::alignof($x)); 26FFI::memset($x, ord("a"), 4); 27var_dump(FFI::string($x, 4)); 28 29echo "\n"; 30 31$y = FFI::new("int[2]"); 32$y[0] = 6; 33var_dump($y[0]); 34var_dump(FFI::typeof($y[0])); 35var_dump(FFI::cast("int8_t[4]", $y[0])); 36$p = FFI::addr($y[0]); 37var_dump($p); 38$p[0] += 2; 39var_dump($y[0]); 40var_dump(FFI::sizeof($y[0])); 41var_dump(FFI::alignof($y[0])); 42FFI::memset($y[0], ord("b"), 4); 43var_dump(FFI::string($y[0], 4)); 44 45echo "\n"; 46 47var_dump(FFI::memcmp($x, $y[0], 4)); 48FFI::memcpy($x, $y[0], 4); 49var_dump(FFI::memcmp($x, $y[0], 4)); 50?> 51--EXPECTF-- 52object(FFI\CData:int32_t)#%d (1) { 53 ["cdata"]=> 54 int(5) 55} 56object(FFI\CType:int32_t)#%d (0) { 57} 58object(FFI\CData:int8_t[4])#%d (4) { 59 [0]=> 60 int(5) 61 [1]=> 62 int(0) 63 [2]=> 64 int(0) 65 [3]=> 66 int(0) 67} 68object(FFI\CData:int32_t*)#%d (1) { 69 [0]=> 70 int(5) 71} 72object(FFI\CData:int32_t)#%d (1) { 73 ["cdata"]=> 74 int(7) 75} 76int(4) 77int(4) 78string(4) "aaaa" 79 80int(6) 81object(FFI\CType:int32_t)#%d (0) { 82} 83object(FFI\CData:int8_t[4])#%d (4) { 84 [0]=> 85 int(6) 86 [1]=> 87 int(0) 88 [2]=> 89 int(0) 90 [3]=> 91 int(0) 92} 93object(FFI\CData:int32_t*)#%d (1) { 94 [0]=> 95 int(6) 96} 97int(8) 98int(4) 99int(4) 100string(4) "bbbb" 101 102int(-1) 103int(0) 104