diff --git a/src/BaseHtmlElement.php b/src/BaseHtmlElement.php
index 41b6e4b5..ddc84107 100644
--- a/src/BaseHtmlElement.php
+++ b/src/BaseHtmlElement.php
@@ -2,6 +2,7 @@
namespace ipl\Html;
+use ReflectionException;
use RuntimeException;
/**
@@ -75,6 +76,9 @@ abstract class BaseHtmlElement extends HtmlDocument
/** @var string Tag of element. Set this property in order to provide the element's tag when extending this class */
protected $tag;
+ /** @var self */
+ private $selfRef;
+
/**
* Get the attributes of the element
*
@@ -83,6 +87,8 @@ abstract class BaseHtmlElement extends HtmlDocument
public function getAttributes()
{
if ($this->attributes === null) {
+ $this->selfRef = $this;
+
$default = $this->getDefaultAttributes();
if (empty($default)) {
$this->attributes = new Attributes();
@@ -353,12 +359,19 @@ public function renderUnwrapped()
);
}
+ /**
+ * @throws ReflectionException
+ */
public function __clone()
{
parent::__clone();
if ($this->attributes !== null) {
$this->attributes = clone $this->attributes;
+
+ $this->attributes->rebind($this->selfRef, $this);
}
+
+ $this->selfRef = $this;
}
}