File tree Expand file tree Collapse file tree 2 files changed +28
-8
lines changed Expand file tree Collapse file tree 2 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ class Context
49
49
/**
50
50
* Prototypical inheritance for properties.
51
51
*/
52
- private ?Context $ parent ;
52
+ protected ?Context $ parent ;
53
53
54
54
public function __construct (array $ properties = [], ?Context $ parent = null )
55
55
{
@@ -183,16 +183,22 @@ public function getDebugLocation(): string
183
183
return $ location ;
184
184
}
185
185
186
- /**
187
- * Excludes `reflector` property.
188
- */
189
186
public function __serialize (): array
190
187
{
191
- $ data = (array ) $ this ;
192
- $ data ['reflector ' ] = null ;
193
- unset($ data ['reflector ' ]);
188
+ return array_filter (get_object_vars ($ this ), function ($ value ): bool {
189
+ $ rc = is_object ($ value ) ? new \ReflectionClass ($ value ) : null ;
190
+
191
+ return (!$ rc || !$ rc ->isAnonymous ())
192
+ && !$ value instanceof \Reflector
193
+ && !$ value instanceof \Closure;
194
+ });
195
+ }
194
196
195
- return $ data ;
197
+ public function __unserialize (array $ data ): void
198
+ {
199
+ foreach ($ data as $ name => $ value ) {
200
+ $ this ->{$ name } = $ value ;
201
+ }
196
202
}
197
203
198
204
/**
Original file line number Diff line number Diff line change @@ -68,4 +68,18 @@ public function testDebugLocation(): void
68
68
$ customerPropertyFirstName ->_context ->getDebugLocation ()
69
69
);
70
70
}
71
+
72
+ // -------------------------------------------------------------------------
73
+
74
+ public function testSerialize (): void
75
+ {
76
+ $ context = new Context (['filename ' => __FILE__ ], $ this ->getContext ());
77
+ $ serialized = serialize ($ context );
78
+ $ unserialized = unserialize ($ serialized );
79
+
80
+ $ this ->assertEquals ($ serialized , serialize ($ unserialized ));
81
+ $ this ->assertInstanceOf (Context::class, $ unserialized ->root ());
82
+ $ this ->assertNotSame ($ unserialized , $ unserialized ->root ());
83
+ $ this ->assertEquals (__FILE__ , $ unserialized ->filename );
84
+ }
71
85
}
You can’t perform that action at this time.
0 commit comments