/** * Clone all elements */ public function __clone() { static::$copies++; $this->open = clone $this->open; $this->close = clone $this->close; foreach ($this->elements as $key => $element) { $this->elements[$key] = clone $element; if ($this->elements[$key] instanceof Element) { $this->elements[$key]->id($this->elements[$key]->attributes['id'] . '-copy-' . static::$copies); $this->elements[$key]->open = $this->open; } } $this->open->name($this->open->name . '-copy-' . static::$copies); }