xref: /PHP-8.2/ext/spl/tests/gh10907.phpt (revision 47b3fe47)
1--TEST--
2GH-10907 (Unable to serialize processed SplFixedArrays in PHP 8.2.4)
3--FILE--
4<?php
5echo "Test without rebuilding properties\n";
6$array = new SplFixedArray(2);
7$array[0] = "test value 1";
8$array[1] = "test value 2";
9var_dump(serialize($array));
10var_dump(unserialize(serialize($array)));
11var_dump($array);
12
13echo "=================\n";
14
15echo "Test with rebuilding properties\n";
16$array = new SplFixedArray(2);
17$array[0] = "test value 1";
18$array[1] = "test value 2";
19var_dump($array); // Rebuilds properties
20var_dump(serialize($array));
21var_dump(unserialize(serialize($array)));
22var_dump($array);
23
24echo "=================\n";
25
26echo "Test with partially rebuilding properties\n";
27$array = new SplFixedArray(3);
28$array[0] = "test value 1";
29var_dump($array); // Rebuilds properties
30$array[1] = "test value 2";
31var_dump(serialize($array));
32var_dump(unserialize(serialize($array)));
33var_dump($array);
34
35echo "=================\n";
36
37echo "Test with adding members\n";
38#[AllowDynamicProperties]
39class MySplFixedArray extends SplFixedArray {
40    public string $my_string = "my_string_value";
41}
42$array = new MySplFixedArray(3);
43$array->my_dynamic_property = "my_dynamic_property_value";
44$array[0] = "test value 1";
45$array[1] = "test value 2";
46var_dump(serialize($array));
47var_dump(unserialize(serialize($array)));
48var_dump($array);
49?>
50--EXPECT--
51Test without rebuilding properties
52string(73) "O:13:"SplFixedArray":2:{i:0;s:12:"test value 1";i:1;s:12:"test value 2";}"
53object(SplFixedArray)#2 (2) {
54  [0]=>
55  string(12) "test value 1"
56  [1]=>
57  string(12) "test value 2"
58}
59object(SplFixedArray)#1 (2) {
60  [0]=>
61  string(12) "test value 1"
62  [1]=>
63  string(12) "test value 2"
64}
65=================
66Test with rebuilding properties
67object(SplFixedArray)#2 (2) {
68  [0]=>
69  string(12) "test value 1"
70  [1]=>
71  string(12) "test value 2"
72}
73string(73) "O:13:"SplFixedArray":2:{i:0;s:12:"test value 1";i:1;s:12:"test value 2";}"
74object(SplFixedArray)#1 (2) {
75  [0]=>
76  string(12) "test value 1"
77  [1]=>
78  string(12) "test value 2"
79}
80object(SplFixedArray)#2 (2) {
81  [0]=>
82  string(12) "test value 1"
83  [1]=>
84  string(12) "test value 2"
85}
86=================
87Test with partially rebuilding properties
88object(SplFixedArray)#1 (3) {
89  [0]=>
90  string(12) "test value 1"
91  [1]=>
92  NULL
93  [2]=>
94  NULL
95}
96string(79) "O:13:"SplFixedArray":3:{i:0;s:12:"test value 1";i:1;s:12:"test value 2";i:2;N;}"
97object(SplFixedArray)#2 (3) {
98  [0]=>
99  string(12) "test value 1"
100  [1]=>
101  string(12) "test value 2"
102  [2]=>
103  NULL
104}
105object(SplFixedArray)#1 (3) {
106  [0]=>
107  string(12) "test value 1"
108  [1]=>
109  string(12) "test value 2"
110  [2]=>
111  NULL
112}
113=================
114Test with adding members
115string(180) "O:15:"MySplFixedArray":5:{i:0;s:12:"test value 1";i:1;s:12:"test value 2";i:2;N;s:9:"my_string";s:15:"my_string_value";s:19:"my_dynamic_property";s:25:"my_dynamic_property_value";}"
116object(MySplFixedArray)#1 (5) {
117  ["my_string"]=>
118  string(15) "my_string_value"
119  ["my_dynamic_property"]=>
120  string(25) "my_dynamic_property_value"
121  [0]=>
122  string(12) "test value 1"
123  [1]=>
124  string(12) "test value 2"
125  [2]=>
126  NULL
127}
128object(MySplFixedArray)#2 (5) {
129  ["my_string"]=>
130  string(15) "my_string_value"
131  ["my_dynamic_property"]=>
132  string(25) "my_dynamic_property_value"
133  [0]=>
134  string(12) "test value 1"
135  [1]=>
136  string(12) "test value 2"
137  [2]=>
138  NULL
139}
140