xref: /PHP-8.1/Zend/tests/bug64896.phpt (revision f8d79582)
1--TEST--
2Bug #64896 (Segfault with gc_collect_cycles using unserialize on certain objects)
3--INI--
4zend.enable_gc=1
5--FILE--
6<?php
7$bar = NULL;
8class bad
9{
10    private $_private = array();
11
12    public function __construct()
13    {
14        $this->_private[] = 'php';
15    }
16
17    public function __destruct()
18    {
19        global $bar;
20        $bar = $this;
21    }
22}
23
24$foo = new stdclass;
25$foo->foo = $foo;
26$foo->bad = new bad;
27
28gc_disable();
29
30unserialize(serialize($foo));
31gc_collect_cycles();
32var_dump($bar);
33gc_enable();
34/*  will output:
35object(bad)#4 (1) {
36  ["_private":"bad":private]=>
37  &UNKNOWN:0
38}
39*/
40?>
41--EXPECTF--
42object(bad)#%d (1) {
43  ["_private":"bad":private]=>
44  array(1) {
45    [0]=>
46    string(3) "php"
47  }
48}
49