|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27288 Count returns 1 for array with simple xml
Submitted: 2004-02-17 03:50 UTC Modified: 2004-02-17 06:29 UTC
From: marcels at korton dot nl Assigned:
Status: Not a bug Package: XML related
PHP Version: 5.0.0b4 (beta4) OS: Windows 2000 SP3
Private report: No CVE-ID: None
 [2004-02-17 03:50 UTC] marcels at korton dot nl
When I use the count function to get the number of elements in an array it returns 1. It does this only when I use simpleXML. In version 5.0.0b3 it worked fine. 

My example use a book in the xml format. Here is a small part of it

            <title>The Period</title>
            <title>The Mail</title>

This continues for al the chapters within the book.

both part and chapter are array's.

We are using the windows precompiled binaries with Sambar server V6.0 build 11 november 2003

Reproduce code:
$xml_mem = simplexml_load_file('2city11.xml');

	for ($i = 0; $i < count($xml_mem->book->bookbody->part); $i++) {
		for ($j = 0; $j < count($xml_mem->book->bookbody->part[$i]->chapter); $j++) {
			echo $xml_mem->book->bookbody->part[$i]->chapter[$j]->chapheader->title,'<br>';

Expected result:
The Period
The Mail
The Night Shadows
The Preparation
The Wine-shop
The Shoemaker
Five Years Later
A Sight
A Disappointment


Actual result:
The Period


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-17 06:11 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try avoid embedding huge scripts into the report.

 [2004-02-17 06:29 UTC]
Arrays are no longer returned. The objects implement iterators so use foreach, ie:

foreach ($xml_mem->book->bookbody->part as $part) {
   foreach($part->chapter as $chapter) {
      echo $chapter->chapheader->title.'<br>';
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Dec 07 21:04:14 2022 UTC