1--TEST--
2__serialize() mechanism (004): Delayed __unserialize() calls
3--FILE--
4<?php
5
6#[AllowDynamicProperties]
7class Wakeup {
8    public $data;
9    public function __construct(array $data) {
10        $this->data = $data;
11    }
12    public function __wakeup() {
13        echo "__wakeup() called\n";
14        var_dump($this->data);
15        $this->woken_up = true;
16    }
17}
18
19#[AllowDynamicProperties]
20class Unserialize {
21    public $data;
22    public function __construct(array $data) {
23        $this->data = $data;
24    }
25    public function __serialize() {
26        return $this->data;
27    }
28    public function __unserialize(array $data) {
29        $this->data = $data;
30        echo "__unserialize() called\n";
31        var_dump($this->data);
32        $this->unserialized = true;
33    }
34}
35
36$obj = new Wakeup([new Unserialize([new Wakeup([new Unserialize([])])])]);
37var_dump($s = serialize($obj));
38var_dump(unserialize($s));
39
40?>
41--EXPECT--
42string(126) "O:6:"Wakeup":1:{s:4:"data";a:1:{i:0;O:11:"Unserialize":1:{i:0;O:6:"Wakeup":1:{s:4:"data";a:1:{i:0;O:11:"Unserialize":0:{}}}}}}"
43__unserialize() called
44array(0) {
45}
46__wakeup() called
47array(1) {
48  [0]=>
49  object(Unserialize)#8 (2) {
50    ["data"]=>
51    array(0) {
52    }
53    ["unserialized"]=>
54    bool(true)
55  }
56}
57__unserialize() called
58array(1) {
59  [0]=>
60  object(Wakeup)#7 (2) {
61    ["data"]=>
62    array(1) {
63      [0]=>
64      object(Unserialize)#8 (2) {
65        ["data"]=>
66        array(0) {
67        }
68        ["unserialized"]=>
69        bool(true)
70      }
71    }
72    ["woken_up"]=>
73    bool(true)
74  }
75}
76__wakeup() called
77array(1) {
78  [0]=>
79  object(Unserialize)#6 (2) {
80    ["data"]=>
81    array(1) {
82      [0]=>
83      object(Wakeup)#7 (2) {
84        ["data"]=>
85        array(1) {
86          [0]=>
87          object(Unserialize)#8 (2) {
88            ["data"]=>
89            array(0) {
90            }
91            ["unserialized"]=>
92            bool(true)
93          }
94        }
95        ["woken_up"]=>
96        bool(true)
97      }
98    }
99    ["unserialized"]=>
100    bool(true)
101  }
102}
103object(Wakeup)#5 (2) {
104  ["data"]=>
105  array(1) {
106    [0]=>
107    object(Unserialize)#6 (2) {
108      ["data"]=>
109      array(1) {
110        [0]=>
111        object(Wakeup)#7 (2) {
112          ["data"]=>
113          array(1) {
114            [0]=>
115            object(Unserialize)#8 (2) {
116              ["data"]=>
117              array(0) {
118              }
119              ["unserialized"]=>
120              bool(true)
121            }
122          }
123          ["woken_up"]=>
124          bool(true)
125        }
126      }
127      ["unserialized"]=>
128      bool(true)
129    }
130  }
131  ["woken_up"]=>
132  bool(true)
133}
134