| Conditions | 6 |
| Paths | 6 |
| Total Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | public function __clone() |
||
| 21 | { |
||
| 22 | // Iterate over all properties on the current object. |
||
| 23 | foreach (get_object_vars($this) as $property => $value) { |
||
| 24 | // If the value of the property is an object then clone it. |
||
| 25 | if (is_object($value)) { |
||
| 26 | $this->$property = clone $value; |
||
| 27 | } elseif (is_array($value)) { |
||
| 28 | // The value is an array that may use objects as values. Iterate |
||
| 29 | // over the array and clone any values that are objects into a |
||
| 30 | // new array. |
||
| 31 | // For some reason, if we try to set $this->$property to an |
||
| 32 | // empty array then update it as we go it ends up being empty. |
||
| 33 | // If we use a new array that we then set as the value of |
||
| 34 | // $this->$property all is well. |
||
| 35 | $new_value = array(); |
||
| 36 | foreach ($value as $index => $array_value) { |
||
| 37 | $new_value[$index] = (is_object($array_value) ? clone $array_value : $array_value); |
||
| 38 | } |
||
| 39 | |||
| 40 | // Set the property to the new array. |
||
| 41 | $this->$property = $new_value; |
||
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 |