- Output for 7.4.25 - 7.4.33, 8.0.12 - 8.0.28, 8.1.0 - 8.1.17, 8.2.0 - 8.2.4
- 0: div 1: div 2: div
- Output for 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.24, 8.0.0 - 8.0.11
- 0: div 1: div 2: null
<?php
$doc = new DOMDocument;
$doc->loadHTML('<html><body id="x"></body></html>');
$body = $doc->getElementById('x');
$div = $doc->createElement('div');
$div->setAttribute('id', 'y');
echo '0: ' . ( $doc->getElementById('y') ? $doc->getElementById('y')->tagName : 'null' ) . PHP_EOL;
$body->appendChild($div);
echo '1: ' . ( $doc->getElementById('y') ? $doc->getElementById('y')->tagName : 'null' ) . PHP_EOL;
$div->setIdAttribute( 'id', true );
echo '2: ' . ( $doc->getElementById('y') ? $doc->getElementById('y')->tagName : 'null' ) . PHP_EOL;