diff --git a/src/Utils/Html.php b/src/Utils/Html.php
index b5e9cc831..81bad0a4e 100644
--- a/src/Utils/Html.php
+++ b/src/Utils/Html.php
@@ -238,8 +238,6 @@ class Html implements \ArrayAccess, \Countable, \IteratorAggregate, HtmlStringab
/** @var array element's attributes */
public $attrs = [];
- public static bool $xhtml = false;
-
/** void elements */
public static $emptyElements = [
'img' => 1, 'hr' => 1, 'br' => 1, 'input' => 1, 'meta' => 1, 'area' => 1, 'embed' => 1, 'keygen' => 1,
@@ -740,7 +738,7 @@ final public function __toString(): string
final public function startTag(): string
{
return $this->name
- ? '<' . $this->name . $this->attributes() . (static::$xhtml && $this->isEmpty ? ' />' : '>')
+ ? '<' . $this->name . $this->attributes() . '>'
: '';
}
@@ -771,11 +769,7 @@ final public function attributes(): string
continue;
} elseif ($value === true) {
- if (static::$xhtml) {
- $s .= ' ' . $key . '="' . $key . '"';
- } else {
- $s .= ' ' . $key;
- }
+ $s .= ' ' . $key;
continue;
} elseif (is_array($value)) {
@@ -810,7 +804,7 @@ final public function attributes(): string
$s .= ' ' . $key . '=' . $q
. str_replace(
['&', $q, '<'],
- ['&', $q === '"' ? '"' : ''', self::$xhtml ? '<' : '<'],
+ ['&', $q === '"' ? '"' : ''', '<'],
$value,
)
. (str_contains($value, '`') && strpbrk($value, ' <>"\'') === false ? ' ' : '')
diff --git a/tests/Utils/Html.basic.phpt b/tests/Utils/Html.basic.phpt
index 6e4f5c1a7..064405e5f 100644
--- a/tests/Utils/Html.basic.phpt
+++ b/tests/Utils/Html.basic.phpt
@@ -14,63 +14,55 @@ require __DIR__ . '/../bootstrap.php';
test('', function () {
- Html::$xhtml = true;
$el = Html::el('img')->src('image.gif')->alt('');
- Assert::same('', (string) $el);
- Assert::same('', $el->toHtml());
- Assert::same('', $el->startTag());
+ Assert::same('', (string) $el);
+ Assert::same('', $el->toHtml());
+ Assert::same('', $el->startTag());
Assert::same('', $el->endTag());
});
test('', function () {
- Html::$xhtml = true;
$el = Html::el('img')->setAttribute('src', 'image.gif')->setAttribute('alt', '');
- Assert::same('', (string) $el);
- Assert::same('', $el->startTag());
+ Assert::same('', (string) $el);
+ Assert::same('', $el->startTag());
Assert::same('', $el->endTag());
});
test('', function () {
- Html::$xhtml = true;
$el = Html::el('img')->accesskey(0, true)->alt('alt', false);
- Assert::same('', (string) $el);
- Assert::same('', (string) $el->accesskey(1, true));
- Assert::same('', (string) $el->accesskey(1, false));
- Assert::same('', (string) $el->accesskey(0, true));
- Assert::same('', (string) $el->accesskey(0));
+ Assert::same('', (string) $el);
+ Assert::same('', (string) $el->accesskey(1, true));
+ Assert::same('', (string) $el->accesskey(1, false));
+ Assert::same('', (string) $el->accesskey(0, true));
+ Assert::same('', (string) $el->accesskey(0));
unset($el->accesskey);
- Assert::same('', (string) $el);
+ Assert::same('', (string) $el);
});
test('', function () {
- Html::$xhtml = true;
$el = Html::el('img')->appendAttribute('accesskey', 0)->setAttribute('alt', false);
- Assert::same('', (string) $el);
- Assert::same('', (string) $el->appendAttribute('accesskey', 1));
- Assert::same('', (string) $el->appendAttribute('accesskey', 1, false));
- Assert::same('', (string) $el->appendAttribute('accesskey', 0));
- Assert::same('', (string) $el->setAttribute('accesskey', 0));
- Assert::same('', (string) $el->removeAttribute('accesskey'));
+ Assert::same('', (string) $el);
+ Assert::same('', (string) $el->appendAttribute('accesskey', 1));
+ Assert::same('', (string) $el->appendAttribute('accesskey', 1, false));
+ Assert::same('', (string) $el->appendAttribute('accesskey', 0));
+ Assert::same('', (string) $el->setAttribute('accesskey', 0));
+ Assert::same('', (string) $el->removeAttribute('accesskey'));
});
test('', function () {
$el = Html::el('img')->src('image.gif')->alt('')->setText('any content');
- Assert::same('', (string) $el);
- Assert::same('', $el->startTag());
- Assert::same('', $el->endTag());
-
- Html::$xhtml = false;
Assert::same('', (string) $el);
+ Assert::same('', $el->startTag());
+ Assert::same('', $el->endTag());
});
test('', function () {
- Html::$xhtml = false;
$el = Html::el('img')->setSrc('image.gif')->setAlt('alt1')->setAlt('alt2');
Assert::same('', (string) $el);
Assert::same('image.gif', $el->getSrc());
@@ -104,10 +96,6 @@ test('small & big numbers', function () {
test('attributes escaping', function () {
- Html::$xhtml = true;
- Assert::same('', (string) Html::el('a')->one('"')->two("'")->three('<>')->four('&'));
-
- Html::$xhtml = false;
Assert::same('', (string) Html::el('a')->one('"')->two("'")->three('<>')->four('&'));
Assert::same('', (string) Html::el('a')->one('``xx')); // mXSS
});