On Dec 1, 2003, at 12:51 PM, Adam Maccabee Trachtenberg wrote:


On Mon, 1 Dec 2003, Stanislav Malyshev wrote:

AMT>> $s = simplexml_load_file('file.xml');
AMT>> $s->person->xsearch('/my/xpath/query');

This makes fetch for read.

I'm with Andi and George. We should just fix SimpleXML to return strings instead of objects when there are no descendant nodes.

Then, $s->person would return an object if there were other nodes to
examine and a string if it was the leaf.

[puts on evil twin hat]
To play devil's advocate to the idea - the problem with it is that it requires a bunch of extra code when examining an unknown document. This is similar to the (promised by Sterling to be fixed) quirk of SimpleXML returning a string when a chile has a single descendent of a given name and an array otherwise. This seems intuitive at first, but means that you need to always check the type of your value before you use it. The same problem exists here.


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to