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