File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-12265 (Cloning an object breaks serialization recursion)
3
+ --FILE--
4
+ <?php
5
+
6
+ class A {
7
+ public function __construct (public B $ x ) {
8
+ }
9
+ }
10
+
11
+ class B {
12
+ public A $ a ;
13
+
14
+ public function __serialize ()
15
+ {
16
+ return ['a ' => new A ($ this )];
17
+ }
18
+ }
19
+
20
+ $ b = new B ();
21
+ $ sb = serialize ($ b );
22
+ $ scb = serialize (clone $ b );
23
+
24
+ printf ("serialized original: %s \n" , $ sb );
25
+ printf ("serialized clone : %s \n" , $ scb );
26
+
27
+ ?>
28
+ --EXPECT--
29
+ serialized original: O:1:"B":1:{s:1:"a";O:1:"A":1:{s:1:"x";r:1;}}
30
+ serialized clone : O:1:"B":1:{s:1:"a";O:1:"A":1:{s:1:"x";r:1;}}
Original file line number Diff line number Diff line change @@ -1314,9 +1314,11 @@ PHP_FUNCTION(serialize)
1314
1314
Z_PARAM_ZVAL (struc )
1315
1315
ZEND_PARSE_PARAMETERS_END ();
1316
1316
1317
+ Z_TRY_ADDREF_P (struc );
1317
1318
PHP_VAR_SERIALIZE_INIT (var_hash );
1318
1319
php_var_serialize (& buf , struc , & var_hash );
1319
1320
PHP_VAR_SERIALIZE_DESTROY (var_hash );
1321
+ Z_TRY_DELREF_P (struc );
1320
1322
1321
1323
if (EG (exception )) {
1322
1324
smart_str_free (& buf );
You can’t perform that action at this time.
0 commit comments