ID: 30731
Updated by: [EMAIL PROTECTED]
Reported By: jarkko dot laiho at iki dot fi
-Status: Open
+Status: Wont fix
Bug Type: Feature/Change Request
Operating System: *
-PHP Version: 5.0.2
+PHP Version: 5.*
Assigned To: helly
New Comment:
We do not know whether to count elements or arrays and we also do not
know whether to count recursive or not. Thus we cannot implement
Countable.
Previous Comments:
------------------------------------------------------------------------
[2004-11-09 10:15:53] jarkko dot laiho at iki dot fi
Description:
------------
SimpleXML objects should implement the Countable interface in order to
work properly with the count() function.
The comments of bug #30113, "ArrayAccess interface does not implement
count functionality", imply that the Countable interface appears in PHP
5.1 and is not yet available in 5.0.2. Therefore, the behaviour of the
repro code below (returning 1 for count() instead of 3) is not a bug
for 5.0.2, since it is expected behaviour for count() to return 1 when
given an object as its parameter. However, given the pseudo-array
nature of a SimpleXML object, a count() of 3 would be very convenient
indeed in many situations.
I was unable to find a mention of Countable getting implemented for
SimpleXML objects in 5.1, so I'm submitting this request for
consideration.
(Note: in the code below, there would naturally be trivial ways to get
a proper count for the $xml->wibblet->somesuch elements, but the code
is meant to merely illustrate the described issue.)
Reproduce code:
---------------
<?php
$xmlstr = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<testdata>
<wibblet>
<somesuch>random data</somesuch>
<somesuch>more random data</somesuch>
<somesuch>not that random</somesuch>
</wibblet>
</testdata>
XML;
$xml = simplexml_load_string($xmlstr);
foreach($xml->wibblet->somesuch as $somesuch) {
echo $somesuch;
echo "<br />";
}
echo "Count: " . count($xml->wibblet->somesuch);
?>
Expected result:
----------------
random data
more random data
not that random
Count: 3
Actual result:
--------------
random data
more random data
not that random
Count: 1
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30731&edit=1