#30731 [NEW]: SimpleXML objects should implement the Countable interface

From: Date: Tue, 09 Nov 2004 09:15:57 +0000
Subject: #30731 [NEW]: SimpleXML objects should implement the Countable interface
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-68836@lists.php.net to get a copy of this message
From: jarkko dot laiho at iki dot fi Operating system: All PHP version: 5.0.2 PHP Bug Type: Feature/Change Request Bug description: SimpleXML objects should implement the Countable interface 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 bug report at http://bugs.php.net/?id=30731&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30731&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30731&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30731&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=30731&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=30731&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=30731&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=30731&r=needscript Try newer version: http://bugs.php.net/fix.php?id=30731&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=30731&r=support Expected behavior: http://bugs.php.net/fix.php?id=30731&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=30731&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=30731&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=30731&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30731&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=30731&r=dst IIS Stability: http://bugs.php.net/fix.php?id=30731&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=30731&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=30731&r=float MySQL Configuration Error: http://bugs.php.net/fix.php?id=30731&r=mysqlcfg

« previous php.bugs (#68836) next »