Re: SimpleXML and Default Cast To String
| From: | Christian Schneider | Date: | Tue, 13 Jan 2004 01:21:06 +0000 |
| Subject: | Re: SimpleXML and Default Cast To String | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-7033@lists.php.net to get a copy of this message | ||
Sterling Hughes wrote:
The problem with simplexml_xpath_query returning an array is that how do you signify failure and an empty set. In order for you to have code that uses foreach() it would need to return an empty set on failure in order to avoid warnings.My preferred solution would be 1) return an array (including empty array for empty result set) 2) return null for error. This way one can distinguish between error and empty result set if needed and cast to array if it doesn't matter, e.g. for foreach. To me null is the natural way of signalling an invalid value, see also NULL in SQL. - Chris