public function setValue($value) { if (is_array($value)) { $value = new ArrayObject($value); } $current = $this->subform->getFormElements(); foreach (array_keys($current) as $key) { $this->subform->offsetUnset($key); } if ($value instanceof ArrayObject) { $values = $value->toArray(); } elseif ($value instanceof Traversable) { $values = iterator_to_array($value); } else { $values = (array) $value; } static $meh = 0; if ($meh++ > 40) { throw new \Exception("Meh"); } foreach ($values as $k => $v) { $element = array_key_exists($k, $current) ? $current[$k] : Misc::deepClone($this->newelement); $element->setValue($v); $value->offsetSet($k, $element->getValue(FALSE)); $this->subform->offsetSet($k, $element); } return parent::setValue($value); }
public function testDeepCloneWithMagicMethod() { $a = new LoopsMiscTest_Mock(); $b = new LoopsMiscTest_Mock2(); $c = new LoopsMiscTest_Mock(); $a->o1 = $b; $a->o2 = $c; $b->o1 = $a; $b->o2 = $c; $clone = Misc::deepClone($a); $this->assertSame($a, $clone->o1->o1); $this->assertSame($c, $clone->o1->o2); }