Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:4390 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56169 invoked by uid 1010); 4 Sep 2003 23:43:43 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 56087 invoked from network); 4 Sep 2003 23:43:40 -0000 Received: from unknown (HELO mail.zend.com) (192.117.235.230) by pb1.pair.com with SMTP; 4 Sep 2003 23:43:40 -0000 Received: (qmail 16569 invoked from network); 4 Sep 2003 23:43:32 -0000 Received: from localhost (HELO zeev-laptop.zend.com) (127.0.0.1) by localhost with SMTP; 4 Sep 2003 23:43:32 -0000 Reply-To: zeev@zend.com Message-ID: <5.1.0.14.2.20030905024226.08f9e8b8@localhost> X-Sender: zeev@localhost X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Fri, 05 Sep 2003 02:49:11 +0300 To: Shane Caraveo Cc: Sterling Hughes ,internals@lists.php.net In-Reply-To: <3F57CABD.2050409@caraveo.com> References: <1062672312.8610.54.camel@hasele> <1062672312.8610.54.camel@hasele> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [PHP-DEV] SimpleXML bug From: zeev@zend.com (Zeev Suraski) We can (and I think we should) solve the attribute/child node ambiguity using the new array-syntax overloading, i.e., use $root['child'] for the attribute, and $root->child for nested elements. We should definitely stay away from having to use functions, either way. As for the array behavior, it's trickier, we need to think about it. Using an object that can cast itself to an array and implements the 'get' method (to fetch its value) may be the right answer. Zeev At 02:29 05/09/2003, Shane Caraveo wrote: >The problem is one of simplicity ;) >I ran into the same problem a couple days ago. In the two examples, an >array of element 'child' is expected. That array may be one or more >elements. SimpleXML turns multiple children of the same element name into >array's, but a single child is not. I'm not sure what the right answere >is for it though, other than conditionaly checking for a single child. > >There's a part of me that thinks that children should be accessed via a >function, but then you start getting dom-like: > >$root->childNodes()[0] > >and it always works. It also prevents problems with something like: > > > abcd > > >Shane > >Sterling Hughes wrote: >>Zeev seems to be working on foreach and simplexml, but the above >>behaviour is the correct one. Why should the first loop? If I did: >>>foreach ("hello" as $world) { >> var_dump($world); >>} >>?> >>what would i get? >>-Sterling >>On Thu, 2003-09-04 at 18:24, Sebastian Bergmann wrote: >> >>> The following script >>> >>> >> $root = simplexml_load_string(' >>> >>> >>> >>> '); >>> >>> foreach ($root->child as $child) { >>> var_dump($child); >>> } >>> ?> >>> >>> does not print anything while >>> >>> >> $root = simplexml_load_string(' >>> >>> >>> >>> >>> '); >>> >>> foreach ($root->child as $child) { >>> var_dump($child); >>> } >>> ?> >>> >>> correctly prints >>> >>> object(simplexml_element)#2 (0) { >>> } >>> object(simplexml_element)#3 (0) { >>> } >>> >>>-- Sebastian Bergmann >>>http://sebastian-bergmann.de/ http://phpOpenTracker.de/ >>> >>>Das Buch zu PHP 5: http://professionelle-softwareentwicklung-mit-php5.de/ > >-- >PHP Internals - PHP Runtime Development Mailing List >To unsubscribe, visit: http://www.php.net/unsub.php