ZF-4631: Zend_Dom_Query_Result breaks foreach() iteration on empty result sets
Description
Example:
$dom = new Zend_Dom_Query('example.html'); foreach ($dom->query('elementdoesnotexist') as $element) { echo $element->getAttribute('id'); }
This snippet will crash with fatal error 'Call to a member function getAttribute() on a non-object'.
Why? Because Zend_Dom_Query_Result::valid() returns TRUE for empty result sets. This bug also exists in the latest SVN (rev 12003).
Comments
Posted by Benjamin Eberlei (beberlei) on 2008-11-07T01:35:49.000+0000
Fixed in trunk, added a new TestCase class Zend_Dom_Query_ResultTest for this
Posted by Wil Sinclair (wil) on 2008-11-13T14:10:24.000+0000
Changing issues in preparation for the 1.7.0 release.