File tree Expand file tree Collapse file tree 4 files changed +55
-0
lines changed
src/Symfony/Component/VarExporter Expand file tree Collapse file tree 4 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -332,6 +332,10 @@ public function __clone(): void
332
332
}
333
333
334
334
if ((Registry::$ parentMethods [self ::class] ??= Registry::getParentMethods (self ::class))['clone ' ]) {
335
+ if ($ this ->lazyObjectState ->skippedProperties ) {
336
+ $ this ->initializeLazyObject ();
337
+ }
338
+
335
339
parent ::__clone ();
336
340
}
337
341
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \Component \VarExporter \Tests \Fixtures \LazyGhost ;
4
+
5
+ class MagicCloneClass
6
+ {
7
+ public ?int $ id ;
8
+ public bool $ cloned ;
9
+
10
+ public function __clone ()
11
+ {
12
+ $ this ->id = null ;
13
+ $ this ->cloned = true ;
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \Component \VarExporter \Tests \Fixtures \LazyGhost ;
4
+
5
+ use Symfony \Component \VarExporter \LazyGhostTrait ;
6
+ use Symfony \Component \VarExporter \LazyObjectInterface ;
7
+
8
+ class MagicCloneClassProxy extends MagicCloneClass implements LazyObjectInterface
9
+ {
10
+ use LazyGhostTrait {
11
+ __clone as private __doClone;
12
+ }
13
+
14
+ public function __clone ()
15
+ {
16
+ $ this ->__doClone ();
17
+ }
18
+ }
Original file line number Diff line number Diff line change 19
19
use Symfony \Component \VarExporter \Tests \Fixtures \LazyGhost \ChildTestClass ;
20
20
use Symfony \Component \VarExporter \Tests \Fixtures \LazyGhost \LazyClass ;
21
21
use Symfony \Component \VarExporter \Tests \Fixtures \LazyGhost \MagicClass ;
22
+ use Symfony \Component \VarExporter \Tests \Fixtures \LazyGhost \MagicCloneClassProxy ;
22
23
use Symfony \Component \VarExporter \Tests \Fixtures \LazyGhost \ReadOnlyClass ;
23
24
use Symfony \Component \VarExporter \Tests \Fixtures \LazyGhost \TestClass ;
24
25
@@ -109,6 +110,23 @@ public function testClone()
109
110
$ this ->assertTrue ($ clone ->resetLazyObject ());
110
111
}
111
112
113
+ public function testCloneIsInitializedIfNeeded ()
114
+ {
115
+ $ instance = MagicCloneClassProxy::createLazyGhost (function (MagicCloneClassProxy $ ghost ) {
116
+ if (1 === $ ghost ->id ) {
117
+ $ ghost ->cloned = false ;
118
+ } else {
119
+ $ this ->fail ('Ghost must be initialized before its __clone method is called. ' );
120
+ }
121
+ }, ['id ' => true ]);
122
+ $ instance ->id = 1 ;
123
+
124
+ $ clone = clone $ instance ;
125
+
126
+ $ this ->assertNull ($ clone ->id );
127
+ $ this ->assertTrue ($ clone ->cloned );
128
+ }
129
+
112
130
public function testSerialize ()
113
131
{
114
132
$ instance = ChildTestClass::createLazyGhost (function (ChildTestClass $ ghost ) {
You can’t perform that action at this time.
0 commit comments