Empty xpath nodelist raises foreach error.
| From: | Philip Fletcher | Date: | Wed, 03 Mar 2004 11:29:07 +0000 |
| Subject: | Empty xpath nodelist raises foreach error. | ||
| Groups: | php.xml.dev | ||
| Request: | Send a blank email to php-xml-dev+get-337@lists.php.net to get a copy of this message | ||
When using foreach() with an xpath query, if the xpath result is an empty
set, then foreach raises a 'Warning: Invalid argument supplied for
foreach()' message. This should not really be raised, as (for foreach())
the xpath return should be a valid (but empty)
Would it be possible to return an empty array/iterator/object just to
foreach() so that this message is not raised? (I think w3c says return
null, but they probably weren't considering foreach():)
Otherwise you end up either doing two xpath queries (one to check there is a
result, and another to do the processing without a warning) or assigning
the xpath result to a temporary var and checking that before use (yeuch!).
Philip