Skip to content

Commit 15ff4e8

Browse files
author
Timm Ortloff
committed
BaseHtmlElement: Rebind Attribute callbacks when cloning
1 parent 68c821b commit 15ff4e8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/BaseHtmlElement.php

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ipl\Html;
44

5+
use ReflectionException;
56
use RuntimeException;
67

78
/**
@@ -75,6 +76,9 @@ abstract class BaseHtmlElement extends HtmlDocument
7576
/** @var string Tag of element. Set this property in order to provide the element's tag when extending this class */
7677
protected $tag;
7778

79+
/** @var self */
80+
private $selfRef;
81+
7882
/**
7983
* Get the attributes of the element
8084
*
@@ -83,6 +87,8 @@ abstract class BaseHtmlElement extends HtmlDocument
8387
public function getAttributes()
8488
{
8589
if ($this->attributes === null) {
90+
$this->selfRef = $this;
91+
8692
$default = $this->getDefaultAttributes();
8793
if (empty($default)) {
8894
$this->attributes = new Attributes();
@@ -353,12 +359,19 @@ public function renderUnwrapped()
353359
);
354360
}
355361

362+
/**
363+
* @throws ReflectionException
364+
*/
356365
public function __clone()
357366
{
358367
parent::__clone();
359368

360369
if ($this->attributes !== null) {
361370
$this->attributes = clone $this->attributes;
371+
372+
$this->attributes->rebind($this->selfRef, $this);
362373
}
374+
375+
$this->selfRef = $this;
363376
}
364377
}

0 commit comments

Comments
 (0)