xref: /PHP-8.0/ext/ffi/tests/bug80847.phpt (revision 6800f0a3)
1--TEST--
2Bug #80847 (Nested structs)
3--SKIPIF--
4<?php
5if (!extension_loaded('ffi')) die('skip ffi extension not available');
6if (!extension_loaded('zend-test')) die('skip zend-test extension not available');
7if (PHP_OS_FAMILY == 'Windows' && ((1 << 31) > 0)) die('xfail libffi doesn\'t properly support passing big strctures by value on Windows/64');
8?>
9--FILE--
10<?php
11require_once('utils.inc');
12$header = <<<HEADER
13    typedef struct bug80847_01 {
14        uint64_t b;
15        double c;
16    } bug80847_01;
17
18    typedef struct bug80847_02 {
19        bug80847_01 a;
20    } bug80847_02;
21
22	bug80847_02 ffi_bug80847(bug80847_02 s);
23HEADER;
24
25if (PHP_OS_FAMILY !== 'Windows') {
26    $ffi = FFI::cdef($header);
27} else {
28    try {
29        $ffi = FFI::cdef($header, 'php_zend_test.dll');
30    } catch (FFI\Exception $ex) {
31        $ffi = FFI::cdef($header, ffi_get_php_dll_name());
32    }
33}
34$x = $ffi->new('bug80847_02');
35$x->a->b = 42;
36$x->a->c = 42.5;
37var_dump($x);
38$y = $ffi->ffi_bug80847($x);
39var_dump($x, $y);
40?>
41--EXPECTF--
42object(FFI\CData:struct bug80847_02)#%d (1) {
43  ["a"]=>
44  object(FFI\CData:struct bug80847_01)#%d (2) {
45    ["b"]=>
46    int(42)
47    ["c"]=>
48    float(42.5)
49  }
50}
51object(FFI\CData:struct bug80847_02)#%d (1) {
52  ["a"]=>
53  object(FFI\CData:struct bug80847_01)#%d (2) {
54    ["b"]=>
55    int(42)
56    ["c"]=>
57    float(42.5)
58  }
59}
60object(FFI\CData:struct bug80847_02)#%d (1) {
61  ["a"]=>
62  object(FFI\CData:struct bug80847_01)#%d (2) {
63    ["b"]=>
64    int(52)
65    ["c"]=>
66    float(32.5)
67  }
68}
69