File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,19 @@ class DeepCopy
2525     */ 
2626    private  $ filters
2727
28+     private  $ skipUncloneablefalse ;
29+ 
30+     /** 
31+      * Cloning uncloneable properties won't throw exception. 
32+      * @param $skipUncloneable 
33+      * @return $this 
34+      */ 
35+     public  function  skipUncloneable ($ skipUncloneabletrue )
36+     {
37+         $ this skipUncloneable  = $ skipUncloneable
38+         return  $ this 
39+     }
40+ 
2841    /** 
2942     * Perform a deep copy of the object. 
3043     * @param object $object 
@@ -92,9 +105,9 @@ private function copyObject($object)
92105
93106        $ reflectedObjectnew  \ReflectionObject ($ object
94107
95-         if  (!$ reflectedObjectisCloneable ()) {
108+         if  (!$ reflectedObjectisCloneable ()  and   $ this -> skipUncloneable ) {
96109            $ this hashMap [$ objectHash$ object
97-             return  $ object             
110+             return  $ object
98111        }
99112
100113        $ newObjectclone  $ object
Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ public function testNonClonableItems()
9595    {
9696        $ anew  \ReflectionClass ('DeepCopyTest\A ' );
9797        $ deepCopynew  DeepCopy ();
98-         $ a2$ deepCopycopy ($ a
98+         $ a2$ deepCopyskipUncloneable ()-> copy ($ a
9999        $ this assertSame ($ a$ a2
100100    }
101101
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments