diff --git a/src/PHPHtmlParser/Dom/Tag.php b/src/PHPHtmlParser/Dom/Tag.php
index 2aeb6aa8..35566b74 100644
--- a/src/PHPHtmlParser/Dom/Tag.php
+++ b/src/PHPHtmlParser/Dom/Tag.php
@@ -326,13 +326,13 @@ public function makeOpeningTag()
foreach (\array_keys($this->attr) as $key) {
try {
$attributeDTO = $this->getAttribute($key);
+ $val = $attributeDTO->getValue();
} catch (AttributeNotFoundException $e) {
// attribute that was in the array not found in the array... let's continue.
continue;
} catch (\TypeError $e) {
- $val = null;
+ $val = null;
}
- $val = $attributeDTO->getValue();
if (\is_null($val)) {
$return .= ' ' . $key;
} elseif ($attributeDTO->isDoubleQuote()) {