Skip to content

DOMDocument::loadHTML fails with "Memory allocation failed" on self-closing elements #18151

@aliechti

Description

@aliechti

Description

The following code:

<?php
declare(strict_types=1);

$content = '<div/><div/>';

$dom = new \DOMDocument();
$dom->loadHTML(
    $content,
    LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD
);

echo $dom->saveHTML();

Resulted in this output:

PHP Warning:  DOMDocument::loadHTML(): Memory allocation failed in Entity, line: 1 in /mnt/projects/limsophy-web/test.php on line 7
<div></div>

But I expected this output instead:

<div><div></div></div>

PHP Version

PHP 8.4.4

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions