xref: /PHP-8.0/ext/ffi/tests/027.phpt (revision d30cd7d7)
1--TEST--
2FFI 027: Incomplete and variable length arrays
3--SKIPIF--
4<?php require_once('skipif.inc'); ?>
5--INI--
6ffi.enable=1
7--FILE--
8<?php
9try {
10    $p = FFI::new("int[*]");
11    echo "ok\n";
12} catch (Throwable $e) {
13    echo get_class($e) . ": " . $e->getMessage()."\n";
14}
15try {
16    FFI::cdef("static int (*foo)[*];");
17    echo "ok\n";
18} catch (Throwable $e) {
19    echo get_class($e) . ": " . $e->getMessage()."\n";
20}
21try {
22    FFI::cdef("typedef int foo[*];");
23    echo "ok\n";
24} catch (Throwable $e) {
25    echo get_class($e) . ": " . $e->getMessage()."\n";
26}
27try {
28    FFI::cdef("static void foo(int[*][*]);");
29    echo "ok\n";
30} catch (Throwable $e) {
31    echo get_class($e) . ": " . $e->getMessage()."\n";
32}
33try {
34    var_dump(FFI::sizeof(FFI::new("int[0]")));
35} catch (Throwable $e) {
36    echo get_class($e) . ": " . $e->getMessage()."\n";
37}
38try {
39    var_dump(FFI::sizeof(FFI::new("int[]")));
40} catch (Throwable $e) {
41    echo get_class($e) . ": " . $e->getMessage()."\n";
42}
43try {
44    var_dump(FFI::sizeof(FFI::cast("int[]", FFI::new("int[2]"))));
45} catch (Throwable $e) {
46    echo get_class($e) . ": " . $e->getMessage()."\n";
47}
48try {
49    FFI::cdef("struct _x {int a; int b[];};");
50    echo "ok\n";
51} catch (Throwable $e) {
52    echo get_class($e) . ": " . $e->getMessage()."\n";
53}
54try {
55    $f = FFI::cdef("typedef int(*foo)[];");
56    echo "ok\n";
57} catch (Throwable $e) {
58    echo get_class($e) . ": " . $e->getMessage()."\n";
59}
60try {
61    $f = FFI::cdef("typedef int foo[][2];");
62    echo "ok\n";
63} catch (Throwable $e) {
64    echo get_class($e) . ": " . $e->getMessage()."\n";
65}
66try {
67    $f = FFI::cdef("typedef int foo[];");
68    echo "ok\n";
69} catch (Throwable $e) {
70    echo get_class($e) . ": " . $e->getMessage()."\n";
71}
72try {
73    $f = FFI::cdef("static int foo(int[]);");
74    echo "ok\n";
75} catch (Throwable $e) {
76    echo get_class($e) . ": " . $e->getMessage()."\n";
77}
78?>
79--EXPECT--
80FFI\ParserException: "[*]" is not allowed in other than function prototype scope at line 1
81FFI\ParserException: "[*]" is not allowed in other than function prototype scope at line 1
82FFI\ParserException: "[*]" is not allowed in other than function prototype scope at line 1
83ok
84FFI\Exception: Cannot instantiate FFI\CData of zero size
85FFI\ParserException: "[]" is not allowed at line 1
86FFI\ParserException: "[]" is not allowed at line 1
87ok
88ok
89ok
90ok
91ok
92