Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:4389 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38770 invoked by uid 1010); 4 Sep 2003 23:30:27 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 38734 invoked from network); 4 Sep 2003 23:30:27 -0000 Received: from unknown (HELO smtp1.ActiveState.com) (209.17.183.249) by pb1.pair.com with SMTP; 4 Sep 2003 23:30:27 -0000 Received: from smtp3.ActiveState.com (smtp3.ActiveState.com [192.168.3.19]) by smtp1.ActiveState.com (8.12.9/8.12.9) with ESMTP id h84NT1BV014246; Thu, 4 Sep 2003 16:29:01 -0700 (envelope-from shane@caraveo.com) Received: from caraveo.com (leverage.ActiveState.com [192.168.3.203]) by smtp3.ActiveState.com (8.12.9/8.12.9) with ESMTP id h84NT10X027471; Thu, 4 Sep 2003 16:29:01 -0700 Message-ID: <3F57CABD.2050409@caraveo.com> Date: Thu, 04 Sep 2003 16:29:01 -0700 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Sterling Hughes CC: Sebastian Bergmann , internals@lists.php.net References: <1062672312.8610.54.camel@hasele> In-Reply-To: <1062672312.8610.54.camel@hasele> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] SimpleXML bug From: shane@caraveo.com (Shane Caraveo) 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/