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