File size: 1,663 Bytes
1e94262 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | --TEST--
FFI 020: read-only
--EXTENSIONS--
ffi
--INI--
ffi.enable=1
--FILE--
<?php
$ffi = FFI::cdef();
try {
$p = $ffi->new("struct {int x; const int y;}");
$p->x = 1;
$p->y = 1;
echo "ok\n";
} catch (Throwable $e) {
echo get_class($e) . ": " . $e->getMessage()."\n";
}
try {
$p = $ffi->new("struct {const int x; int y;}");
$p->y = 1;
$p->x = 1;
echo "ok\n";
} catch (Throwable $e) {
echo get_class($e) . ": " . $e->getMessage()."\n";
}
try {
$p = $ffi->new("const struct {int x; int y;}");
$p->x = 1;
echo "ok\n";
} catch (Throwable $e) {
echo get_class($e) . ": " . $e->getMessage()."\n";
}
try {
$p = $ffi->new("const int[10]");
$p[1] = 1;
echo "ok\n";
} catch (Throwable $e) {
echo get_class($e) . ": " . $e->getMessage()."\n";
}
try {
$p = $ffi->new("const int * [1]");
$p[0] = null;
echo "ok\n";
} catch (Throwable $e) {
echo get_class($e) . ": " . $e->getMessage()."\n";
}
try {
$p = $ffi->new("int * const [1]");
$p[0] = null;
echo "ok\n";
} catch (Throwable $e) {
echo get_class($e) . ": " . $e->getMessage()."\n";
}
try {
$f = FFI::cdef("typedef int * const t[1];");
$p = $f->new("t");
$p[0] = null;
echo "ok\n";
} catch (Throwable $e) {
echo get_class($e) . ": " . $e->getMessage()."\n";
}
?>
ok
--EXPECT--
FFI\Exception: Attempt to assign read-only field 'y'
FFI\Exception: Attempt to assign read-only field 'x'
FFI\Exception: Attempt to assign read-only location
FFI\Exception: Attempt to assign read-only location
ok
FFI\Exception: Attempt to assign read-only location
FFI\Exception: Attempt to assign read-only location
ok
|