php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34422 simplexml_load_string object to array bug
Submitted: 2005-09-08 09:50 UTC Modified: 2005-09-08 10:02 UTC
From: cyberline at techno4ever dot net Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.0.5 OS: Suse 9.3
Private report: No CVE-ID: None
 [2005-09-08 09:50 UTC] 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
     )
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-08 10:02 UTC] chregu@php.net
use $hosts[] = (string) $listener->HOSTNAME;

$listener->HOSTNAME is an object, echo just automatically 
calls the internal __toString()
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 14:01:29 2024 UTC