1--TEST-- 2GH-7867 (FFI::cast() from pointer to array is broken) 3--EXTENSIONS-- 4ffi 5--INI-- 6ffi.enable=1 7--FILE-- 8<?php 9$value = FFI::new('char[26]'); 10FFI::memcpy($value, implode('', range('a', 'z')), 26); 11 12$slice = FFI::new('char[4]'); 13 14echo 'cast from start' . PHP_EOL; 15FFI::memcpy($slice, $value, 4); 16var_dump($value + 0, $slice, FFI::cast('char[4]', $value)); 17echo PHP_EOL; 18 19echo 'cast with offset' . PHP_EOL; 20FFI::memcpy($slice, $value + 4, 4); 21var_dump($value + 4, $slice, FFI::cast('char[4]', $value + 4)); 22echo PHP_EOL; 23?> 24--EXPECTF-- 25cast from start 26object(FFI\CData:char*)#%d (1) { 27 [0]=> 28 string(1) "a" 29} 30object(FFI\CData:char[4])#%d (4) { 31 [0]=> 32 string(1) "a" 33 [1]=> 34 string(1) "b" 35 [2]=> 36 string(1) "c" 37 [3]=> 38 string(1) "d" 39} 40object(FFI\CData:char[4])#%d (4) { 41 [0]=> 42 string(1) "a" 43 [1]=> 44 string(1) "b" 45 [2]=> 46 string(1) "c" 47 [3]=> 48 string(1) "d" 49} 50 51cast with offset 52object(FFI\CData:char*)#%d (1) { 53 [0]=> 54 string(1) "e" 55} 56object(FFI\CData:char[4])#%d (4) { 57 [0]=> 58 string(1) "e" 59 [1]=> 60 string(1) "f" 61 [2]=> 62 string(1) "g" 63 [3]=> 64 string(1) "h" 65} 66object(FFI\CData:char[4])#%d (4) { 67 [0]=> 68 string(1) "e" 69 [1]=> 70 string(1) "f" 71 [2]=> 72 string(1) "g" 73 [3]=> 74 string(1) "h" 75} 76