xref: /PHP-8.1/ext/ffi/tests/003.phpt (revision bd9f4fa6)
1--TEST--
2FFI 003: Forward tag/typedef declarations
3--EXTENSIONS--
4ffi
5--INI--
6ffi.enable=1
7--FILE--
8<?php
9$ffi = FFI::cdef(<<<EOF
10struct _a;
11struct _a {int x;};
12
13struct _b {int x;};
14struct _b;
15
16typedef struct _c c;
17struct _c {int x;};
18
19struct _d {int x;};
20typedef struct _d d;
21
22struct _e;
23
24struct _f;
25typedef struct _f f;
26EOF
27);
28var_dump($ffi->new("struct _a"));
29var_dump($ffi->new("struct _b"));
30var_dump($ffi->new("c"));
31var_dump($ffi->new("d"));
32try {
33    var_dump($ffi->new("struct _e"));
34} catch (Throwable $e) {
35    echo get_class($e) . ": " . $e->getMessage()."\n";
36}
37try {
38    var_dump($ffi->new("f"));
39} catch (Throwable $e) {
40    echo get_class($e) . ": " . $e->getMessage()."\n";
41}
42echo "ok\n";
43?>
44--EXPECTF--
45object(FFI\CData:struct _a)#%d (1) {
46  ["x"]=>
47  int(0)
48}
49object(FFI\CData:struct _b)#%d (1) {
50  ["x"]=>
51  int(0)
52}
53object(FFI\CData:struct _c)#%d (1) {
54  ["x"]=>
55  int(0)
56}
57object(FFI\CData:struct _d)#%d (1) {
58  ["x"]=>
59  int(0)
60}
61FFI\ParserException: Incomplete struct "_e" at line 1
62FFI\ParserException: Incomplete struct "_f" at line 1
63ok
64