Skip to content

Commit fb8a469

Browse files
committed
Fix an additional problem
1 parent 67eb210 commit fb8a469

File tree

2 files changed

+80
-13
lines changed

2 files changed

+80
-13
lines changed

ext/spl/spl_fixedarray.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,8 @@ PHP_METHOD(SplFixedArray, __serialize)
597597
RETURN_THROWS();
598598
}
599599

600-
uint32_t num_properties =
601-
intern->std.properties ? zend_hash_num_elements(intern->std.properties) : 0;
600+
HashTable *ht = zend_std_get_properties(&intern->std);
601+
uint32_t num_properties = zend_hash_num_elements(ht);
602602
array_init_size(return_value, intern->array.size + num_properties);
603603

604604
/* elements */
@@ -609,17 +609,15 @@ PHP_METHOD(SplFixedArray, __serialize)
609609
}
610610

611611
/* members */
612-
if (intern->std.properties) {
613-
ZEND_HASH_FOREACH_STR_KEY_VAL_IND(intern->std.properties, key, current) {
614-
/* The properties hash table can also contain the array elements if the properties table was already rebuilt.
615-
* In this case we'd have a NULL key. We can't simply use the properties table in all cases because it's
616-
* potentially out of sync (missing elements, or containing removed elements) and might need a rebuild. */
617-
if (key != NULL) {
618-
zend_hash_add_new(Z_ARRVAL_P(return_value), key, current);
619-
Z_TRY_ADDREF_P(current);
620-
}
621-
} ZEND_HASH_FOREACH_END();
622-
}
612+
ZEND_HASH_FOREACH_STR_KEY_VAL_IND(ht, key, current) {
613+
/* If the properties table was already rebuild, it will also contain the
614+
* array elements. The array elements are already added in the above loop.
615+
* We can detect array elements by the fact that their key == NULL. */
616+
if (key != NULL) {
617+
zend_hash_add_new(Z_ARRVAL_P(return_value), key, current);
618+
Z_TRY_ADDREF_P(current);
619+
}
620+
} ZEND_HASH_FOREACH_END();
623621
}
624622

625623
PHP_METHOD(SplFixedArray, __unserialize)

ext/spl/tests/gh10925.phpt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
--TEST--
2+
Properties serialization for SplFixedArray should have updated properties
3+
--FILE--
4+
<?php
5+
#[AllowDynamicProperties]
6+
class MySplFixedArray extends SplFixedArray {
7+
public $x;
8+
public int $y = 3;
9+
}
10+
11+
$x = new MySplFixedArray(2);
12+
var_dump($x->y);
13+
$x->y = 2;
14+
var_dump($x->y);
15+
$serialized = serialize($x);
16+
var_dump($serialized);
17+
var_dump(unserialize($serialized));
18+
19+
$x->dynamic_property = "dynamic_property_value";
20+
$serialized = serialize($x);
21+
var_dump($serialized);
22+
var_dump(unserialize($serialized));
23+
24+
$x->dynamic_property = "dynamic_property_value2";
25+
$x->y = 4;
26+
$serialized = serialize($x);
27+
var_dump($serialized);
28+
var_dump(unserialize($serialized));
29+
?>
30+
--EXPECT--
31+
int(3)
32+
int(2)
33+
string(61) "O:15:"MySplFixedArray":4:{i:0;N;i:1;N;s:1:"x";N;s:1:"y";i:2;}"
34+
object(MySplFixedArray)#2 (4) {
35+
["x"]=>
36+
NULL
37+
["y"]=>
38+
int(2)
39+
[0]=>
40+
NULL
41+
[1]=>
42+
NULL
43+
}
44+
string(115) "O:15:"MySplFixedArray":5:{i:0;N;i:1;N;s:1:"x";N;s:1:"y";i:2;s:16:"dynamic_property";s:22:"dynamic_property_value";}"
45+
object(MySplFixedArray)#2 (5) {
46+
["x"]=>
47+
NULL
48+
["y"]=>
49+
int(2)
50+
["dynamic_property"]=>
51+
string(22) "dynamic_property_value"
52+
[0]=>
53+
NULL
54+
[1]=>
55+
NULL
56+
}
57+
string(116) "O:15:"MySplFixedArray":5:{i:0;N;i:1;N;s:1:"x";N;s:1:"y";i:4;s:16:"dynamic_property";s:23:"dynamic_property_value2";}"
58+
object(MySplFixedArray)#2 (5) {
59+
["x"]=>
60+
NULL
61+
["y"]=>
62+
int(4)
63+
["dynamic_property"]=>
64+
string(23) "dynamic_property_value2"
65+
[0]=>
66+
NULL
67+
[1]=>
68+
NULL
69+
}

0 commit comments

Comments
 (0)