File tree Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1010 - ' 7.1'
1111 - ' 7.2'
1212 - ' 7.3'
13+ - ' 7.4'
1314 - nightly
1415
1516matrix :
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace DeepCopy \f009 ;
4+
5+ class TypedProperty
6+ {
7+ public int $ foo ;
8+ }
Original file line number Diff line number Diff line change @@ -237,6 +237,12 @@ function ($object) {
237237 }
238238
239239 $ property ->setAccessible (true );
240+
241+ // Ignore uninitialized properties (for PHP >7.4)
242+ if (method_exists ($ property , 'isInitialized ' ) && !$ property ->isInitialized ($ object )) {
243+ return ;
244+ }
245+
240246 $ propertyValue = $ property ->getValue ($ object );
241247
242248 // Copy the property
Original file line number Diff line number Diff line change 1616use DeepCopy \f006 ;
1717use DeepCopy \f007 ;
1818use DeepCopy \f008 ;
19+ use DeepCopy \f009 ;
1920use DeepCopy \Filter \KeepFilter ;
2021use DeepCopy \Filter \SetNullFilter ;
2122use DeepCopy \Matcher \PropertyNameMatcher ;
@@ -434,6 +435,35 @@ public function test_it_can_prepend_filter()
434435 $ this ->assertNull ($ copy ->getFoo ());
435436 }
436437
438+ /**
439+ * @ticket https://github.com/myclabs/DeepCopy/issues/143
440+ * @requires PHP 7.4
441+ */
442+ public function test_it_clones_typed_properties ()
443+ {
444+ $ object = new f009 \TypedProperty ();
445+ $ object ->foo = 123 ;
446+
447+ $ deepCopy = new DeepCopy ();
448+ $ copy = $ deepCopy ->copy ($ object );
449+
450+ $ this ->assertSame (123 , $ copy ->foo );
451+ }
452+
453+ /**
454+ * @ticket https://github.com/myclabs/DeepCopy/issues/143
455+ * @requires PHP 7.4
456+ */
457+ public function test_it_ignores_uninitialized_typed_properties ()
458+ {
459+ $ object = new f009 \TypedProperty ();
460+
461+ $ deepCopy = new DeepCopy ();
462+ $ copy = $ deepCopy ->copy ($ object );
463+
464+ $ this ->assertFalse (isset ($ copy ->foo ));
465+ }
466+
437467 private function assertEqualButNotSame ($ expected , $ val )
438468 {
439469 $ this ->assertEquals ($ expected , $ val );
You can’t perform that action at this time.
0 commit comments