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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cyberline at techno4ever dot net
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Thu Dec 26 17:01:31 2024 UTC