1--TEST-- 2FFI 046: FFI::CType reflection API 3--EXTENSIONS-- 4ffi 5--INI-- 6ffi.enable=1 7--FILE-- 8<?php 9$x = FFI::type("uint8_t"); 10var_dump($x->getKind() === $x::TYPE_UINT8); 11var_dump($x->getSize()); 12var_dump($x->getAlignment()); 13 14$x = FFI::type("enum __attribute__((packed)) {a2, b2}"); 15var_dump($x->getKind() === $x::TYPE_ENUM); 16var_dump($x->getEnumKind() === $x::TYPE_UINT8); 17 18$x = FFI::type("char[5]"); 19var_dump($x->getKind() === $x::TYPE_ARRAY); 20var_dump($x->getSize()); 21var_dump($x->getArrayElementType()->getKind() === $x::TYPE_CHAR); 22var_dump($x->getArrayLength()); 23 24$x = FFI::type("void*"); 25var_dump($x->getKind() === $x::TYPE_POINTER); 26var_dump($x->getPointerType()->getKind() === $x::TYPE_VOID); 27 28$x = FFI::type("struct {double x; double y;}"); 29var_dump($x->getKind() === $x::TYPE_STRUCT); 30var_dump(($x->getAttributes() & $x::ATTR_UNION) != 0); 31var_dump($x->getStructFieldNames()); 32var_dump($x->getStructFieldOffset("x")); 33var_dump($x->getStructFieldOffset("y")); 34var_dump($x->getStructFieldType("x")->getKind() == $x::TYPE_DOUBLE); 35var_dump($x->getStructFieldType("y")->getKind() == $x::TYPE_DOUBLE); 36 37$x = FFI::type("union {double x; double y;}"); 38var_dump($x->getKind() === $x::TYPE_STRUCT); 39var_dump(($x->getAttributes() & $x::ATTR_UNION) != 0); 40var_dump($x->getStructFieldNames()); 41var_dump($x->getStructFieldOffset("x")); 42var_dump($x->getStructFieldOffset("y")); 43var_dump($x->getStructFieldType("x")->getKind() == $x::TYPE_DOUBLE); 44var_dump($x->getStructFieldType("y")->getKind() == $x::TYPE_DOUBLE); 45 46$x = FFI::type("void (*)(double,int32_t)"); 47var_dump($x->getKind() === $x::TYPE_POINTER); 48var_dump($x->getPointerType()->getKind() === $x::TYPE_FUNC); 49var_dump($x->getPointerType()->getFuncReturnType()->getKind() === $x::TYPE_VOID); 50var_dump($x->getPointerType()->getFuncParameterCount()); 51var_dump($x->getPointerType()->getFuncParameterType(0)->getKind() === $x::TYPE_DOUBLE); 52var_dump($x->getPointerType()->getFuncParameterType(1)->getKind() === $x::TYPE_SINT32); 53?> 54--EXPECT-- 55bool(true) 56int(1) 57int(1) 58bool(true) 59bool(true) 60bool(true) 61int(5) 62bool(true) 63int(5) 64bool(true) 65bool(true) 66bool(true) 67bool(false) 68array(2) { 69 [0]=> 70 string(1) "x" 71 [1]=> 72 string(1) "y" 73} 74int(0) 75int(8) 76bool(true) 77bool(true) 78bool(true) 79bool(true) 80array(2) { 81 [0]=> 82 string(1) "x" 83 [1]=> 84 string(1) "y" 85} 86int(0) 87int(0) 88bool(true) 89bool(true) 90bool(true) 91bool(true) 92bool(true) 93int(2) 94bool(true) 95bool(true) 96