Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:26543 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55819 invoked by uid 1010); 13 Nov 2006 15:29:42 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 55804 invoked from network); 13 Nov 2006 15:29:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Nov 2006 15:29:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=jochem@iamjochem.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=jochem@iamjochem.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain iamjochem.com from 194.109.193.121 cause and error) X-PHP-List-Original-Sender: jochem@iamjochem.com X-Host-Fingerprint: 194.109.193.121 mx1.moulin.nl Linux 2.6 Received: from [194.109.193.121] ([194.109.193.121:48920] helo=mx1.moulin.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E6/06-14365-46F88554 for ; Mon, 13 Nov 2006 10:29:41 -0500 Received: from localhost (localhost [127.0.0.1]) by mx1.moulin.nl (Postfix) with ESMTP id 293231FA9EA; Mon, 13 Nov 2006 16:29:43 +0100 (CET) X-Virus-Scanned: amavisd-new at moulin.nl Received: from mx1.moulin.nl ([127.0.0.1]) by localhost (mx1.moulin.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vx5MAzKLp71t; Mon, 13 Nov 2006 16:29:39 +0100 (CET) Received: from [192.168.1.101] (bspr.xs4all.nl [194.109.161.228]) by mx1.moulin.nl (Postfix) with ESMTP id 2FFAE1FA9A9; Mon, 13 Nov 2006 16:29:39 +0100 (CET) Message-ID: <45588F5D.2010903@iamjochem.com> Date: Mon, 13 Nov 2006 16:29:33 +0100 User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 To: Stut CC: Sebastian Bergmann , internals@lists.php.net References: <45588119.5080207@gmail.com> In-Reply-To: <45588119.5080207@gmail.com> X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] SimpleXML: A bug or just an annoyance? From: jochem@iamjochem.com (Jochem Maas) Stut wrote: > Sebastian Bergmann wrote: >> 1 > 2 $root = simplexml_load_string(''); >> 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 >