Empty xpath nodelist raises foreach error.
[email protected] (Philip Fletcher) Wed, 03 Mar 2004 11:29:07 +0000
| Newsgroups | php.xml.dev |
|---|---|
| Organization | Stutchbury |
| Message-ID | <[email protected]> |
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