Skip to content

Commit 0e87885

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

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

ext/spl/spl_fixedarray.c

Lines changed: 8 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,12 @@ 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 (key != NULL) {
614+
zend_hash_add_new(Z_ARRVAL_P(return_value), key, current);
615+
Z_TRY_ADDREF_P(current);
616+
}
617+
} ZEND_HASH_FOREACH_END();
623618
}
624619

625620
PHP_METHOD(SplFixedArray, __unserialize)

ext/spl/tests/gh10925.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Dynamic 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+
--EXPECT--
20+
int(3)
21+
int(2)
22+
string(61) "O:15:"MySplFixedArray":4:{i:0;N;i:1;N;s:1:"x";N;s:1:"y";i:2;}"
23+
object(MySplFixedArray)#2 (4) {
24+
["x"]=>
25+
NULL
26+
["y"]=>
27+
int(2)
28+
[0]=>
29+
NULL
30+
[1]=>
31+
NULL
32+
}

0 commit comments

Comments
 (0)