xref: /PHP-8.2/ext/ffi/tests/bug79571.phpt (revision bd9f4fa6)
1--TEST--
2Bug #79571 (FFI: var_dumping unions may segfault)
3--EXTENSIONS--
4ffi
5--SKIPIF--
6<?php
7if (pack('S', 0xABCD) !== pack('v', 0xABCD)) {
8    die('skip for little-endian architectures only');
9}
10?>
11--FILE--
12<?php
13$ffi = FFI::cdef(<<<EOF
14    typedef union {
15        int num;
16        char *str;
17    } my_union;
18EOF);
19
20$union = $ffi->new('my_union');
21$union->num = 42;
22var_dump($union);
23var_dump($union->num);
24?>
25--EXPECTF--
26object(FFI\CData:union <anonymous>)#%d (2) {
27  ["num"]=>
28  int(42)
29  ["str"]=>
30  string(4) "0x2a"
31}
32int(42)
33