From: sites at hubmed dot org Operating system: Mac OS X PHP version: 5.2CVS-2008-11-07 (CVS) PHP Bug Type: SimpleXML related Bug description: SimpleXML inconsistent behaviour with multiple XML nodes
Description: ------------ This is a duplicate of bug 45023, which is marked as bogus but needs reopening. I'm seeing the same problem with the latest CVS version: PHP 5.2.7RC2-dev (cli) (built: Nov 7 2008 15:02:08) Mac OS 10.5.5 libxml2 2.6.30 At the moment, it's not possible to check whether a SimpleXML element is an array or an object and iterate appropriately (as foreach() will iterate over both an array and an object). Reproduce code: --------------- $xml = simplexml_load_string('<root><item>a</item><item>b</item></root>'); print_r($xml); foreach ($xml->item as $item) print "\n" . 'Item: ' . (string) $item; print "\n"; print'Type: ' . gettype($xml->item); print "\n"; print is_array($xml->item) ? 'Is an array' : 'Not an array'; print "\n"; print_r($xml->item); print_r($xml->item[1]); Expected result: ---------------- gettype($xml->item) should return 'array', and is_array($xml->item) should return true. $xml->item should retrieve the whole array, not just the first item. Actual result: -------------- SimpleXMLElement Object ( [item] => Array ( [0] => a [1] => b ) ) Item: a Item: b Type: object Not an array SimpleXMLElement Object ( [0] => a ) SimpleXMLElement Object ( [0] => b ) -- Edit bug report at http://bugs.php.net/?id=46517&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46517&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46517&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46517&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=46517&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46517&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=46517&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=46517&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=46517&r=needscript Try newer version: http://bugs.php.net/fix.php?id=46517&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=46517&r=support Expected behavior: http://bugs.php.net/fix.php?id=46517&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=46517&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=46517&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=46517&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46517&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=46517&r=dst IIS Stability: http://bugs.php.net/fix.php?id=46517&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=46517&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=46517&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=46517&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=46517&r=mysqlcfg