#34422 [Opn->Bgs]: simplexml_load_string object to array bug
| From: | chregu@php.net | Date: | Thu, 08 Sep 2005 08:02:12 +0000 |
| Subject: | #34422 [Opn->Bgs]: simplexml_load_string object to array bug | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-84688@lists.php.net to get a copy of this message | ||
ID: 34422
Updated by: chregu@php.net
Reported By: cyberline at techno4ever dot net
-Status: Open
+Status: Bogus
Bug Type: SimpleXML related
Operating System: Suse 9.3
PHP Version: 5.0.5
New Comment:
use $hosts[] = (string) $listener->HOSTNAME;
$listener->HOSTNAME is an object, echo just automatically
calls the internal __toString()
Previous Comments:
------------------------------------------------------------------------
[2005-09-08 09:50:52] cyberline at techno4ever dot net
Description:
------------
When adding a subelement of the xml object to an array, it becomes an
object again? "echo" doesn't return an object ...
Reproduce code:
---------------
$xml = simplexml_load_string($this->xml);
foreach($xml->LISTENERS->LISTENER as $listener) {
echo $listener->HOSTNAME; // Last element in tree
$hosts[] = $listener->HOSTNAME;
}
Expected result:
----------------
127.0.0.1
Array(
[0] => 127.0.0.1
)
Actual result:
--------------
127.0.0.1
Array(
[0] => SimpleXMLElement Object(
[0] => 127.0.0.1
)
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=34422&edit=1