Bug #56239 [Opn->Nab]: count for SimpleXml nodes return wrong value
| From: | yohgaki@php.net | Date: | Wed, 31 Jul 2013 05:22:25 +0000 |
| Subject: | Bug #56239 [Opn->Nab]: count for SimpleXml nodes return wrong value | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-180609@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=56239&edit=1
ID: 56239
Updated by: yohgaki@php.net
Reported by: tim dot lokot at printsoft dot com
Summary: count for SimpleXml nodes return wrong value
-Status: Open
+Status: Not a bug
Type: Bug
-Package: domxml
+Package: *General Issues
Operating System: XP
PHP Version: 5CVS-2004-11-29 (dev)
Block user comment: N
Private report: N
New Comment:
Usage is wrong. Please read
http://jp1.php.net/manual/en/book.simplexml.php
In simplexml, root node is assumed always exists and represented as var. So you
cannot refer to it.
Previous Comments:
------------------------------------------------------------------------
[2004-11-29 23:46:06] tim dot lokot at printsoft dot com
Description:
------------
PHP is 5.0.2 firstly, it wasn't in the list, so I just chose the cvs version.
I am trying to count how many nodes are under another node in an xml document by counting them with
count(). For some reason, even when I have more than one node, it always returns 1. Same with the
children() function.
Basically in my code, I'm trying to prove that Order->OrderLines['NumLines'] ==
count(Order->OrderLines->OrderLine)
Reproduce code:
---------------
XML Fragment:
<Order>
<OrderLines NumLines="2">
<OrderLine Number="1" StampID="435" Quantity="2" />
<OrderLine Number="2" StampID="733" Quantity="5" />
</OrderLines>
</Order>
PHP Code;
$order = $xml->Order; // set previously
count($order->OrderLines->children()))
or
count($order->OrderLines->OrderLine)
Expected result:
----------------
2
Actual result:
--------------
1
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=56239&edit=1