voku/simple_html_dom

Chained find() on empty resultset returns inconsistent results

heldchen opened this issue · 1 comments

What is this feature about (expected vs actual behaviour)?

->find() returns an object even when no match is found... unless you chain it more than 2 times. it would be beneficial if the empty resultset would be consistent no matter how many times you query on an blank result.

How can I reproduce it?

$dom = (new voku\helper\HtmlDomParser())->loadHtml('<div> foo bar </div>');
var_dump($dom->find('span', 0));
var_dump($dom->find('span', 0)->find('span', 0));
var_dump($dom->find('span', 0)->find('span', 0)->find('span', 0));
var_dump($dom->find('span', 0)->find('span', 0)->find('span', 0)->find('span', 0));

output:

object(voku\helper\SimpleHtmlDomBlank)[173]
  protected 'node' => null
  private 'classListCache' (voku\helper\AbstractSimpleHtmlDom) => null

object(voku\helper\SimpleHtmlDomNodeBlank)[184]
  private 'storage' (ArrayObject) => 
    array (size=0)
      empty

null

Fatal error: Uncaught Error: Call to a member function find() on null

Does it take minutes, hours or days to fix?

hours

voku commented

What do you think of this: 6b9fb4a