Stut wrote: > Sebastian Bergmann wrote: >> 1 <?php >> 2 $root = simplexml_load_string('<root id="1"><node/></root>'); >> 3 >> 4 $array = array(); >> 5 $array[$root['id']] = 'value'; >> 6 >> 7 $key = (int)$root['id']; >> 8 $array[$key] = 'value'; >> 9 ?> >> Warning: Illegal offset type in /home/sb/test.php on line 5 >> > > I've not used it much, but I believe you need to cast attributes coming > out of SimpleXML, in this case probably to an int.
that sounds about right. my experience with SimpleXML is that every is either a string, an object, an array depending on how you are looking at it and regardless of the situation auto-casting can be relied on to NOT do what you want/expect ... the most problematic thing I found with simpleXML was the complete lack of means to inspect an objects structure/content using funcs like var_dump() [it seems lots of __toString() magic lays waste to any attempt to look inside the object] from what I gather the described 'annoyance' is indicative of the prescribed SimpleXML behaviour. I personally believe that SimpleXML is too clever and/or intuitive for it's own good - or maybe I'm just incredibly stupid, either way I decided a while back to stick to using the DOM extension for anything XML related because I found it so much easier to use and understand. I guess nothing in live is ever simple ;-) > > -Stut > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php