File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,9 @@ private function copyObject($object)
141141 $ newObject = clone $ object ;
142142 $ this ->hashMap [$ objectHash ] = $ newObject ;
143143
144+ if ($ newObject instanceof \DateTimeInterface) {
145+ return $ newObject ;
146+ }
144147 foreach (ReflectionHelper::getProperties ($ reflectedObject ) as $ property ) {
145148 $ this ->copyObjectProperty ($ newObject , $ property );
146149 }
Original file line number Diff line number Diff line change @@ -42,6 +42,23 @@ public function testPropertyObjectCopy()
4242 $ this ->assertDeepCopyOf ($ o , $ deepCopy ->copy ($ o ));
4343 }
4444
45+ public function testPropertyObjectCopyWithDateTimes ()
46+ {
47+ $ o = new A ();
48+ $ o ->date1 = new \DateTime ();
49+ if (class_exists ('DateTimeImmutable ' )) {
50+ $ o ->date2 = new \DateTimeImmutable ();
51+ }
52+
53+ $ deepCopy = new DeepCopy ();
54+ $ c = $ deepCopy ->copy ($ o );
55+
56+ $ this ->assertDeepCopyOf ($ o , $ c );
57+
58+ $ c ->date1 ->setDate (2015 , 01 , 04 );
59+ $ this ->assertNotEquals ($ c ->date1 , $ o ->date1 );
60+ }
61+
4562 public function testPrivatePropertyOfParentObjectCopy ()
4663 {
4764 $ o = new E ();
You can’t perform that action at this time.
0 commit comments