<?php
$s_htm = '<div class="c1"></div><div class="c2"></div>';
include_once('HtmlDocument.php');
use simplehtmldom\HtmlDocument;
$o_doc = new HtmlDocument();
$o_doc->load($s_htm);
$o_elm1 = $o_doc->find('.c1',0);
echo("an element of class='".($o_elm1->getAttribute('class'))."' was found => ok\n");
$o_elm2 = $o_elm1->find('*',0);
if(NULL === $o_elm2) {
echo("no sub-elements found within div.c1 => ok\n");
} elseif(is_object($o_elm2)) {
echo("a sub-element of class='".($o_elm2->getAttribute('class'))."' was found within div.c1 => bug\n");
}
outputs:
an element of class='c1' was found => ok
a sub-element of class='c2' was found within div.c1 => bug
Expected output:
element of class='c1' was found => ok
no sub-elements found within div.c1 => ok
This bug persists even with well-formed HTML with single root element: