|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29500 Accessing object elements returns object
Submitted: 2004-08-03 05:15 UTC Modified: 2004-08-03 15:39 UTC
Avg. Score:3.8 ± 1.3
Reproduced:35 of 40 (87.5%)
Same Version:11 (31.4%)
Same OS:8 (22.9%)
From: lists at cyberlot dot net Assigned:
Status: Wont fix Package: SimpleXML related
PHP Version: 5.0.0 OS: Fedora Core 2
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-08-03 05:15 UTC] lists at cyberlot dot net
When using simplexml to access a element the returned object it returns a object instead of a string

Have to type cast it as a (string) to get the information back, Should not have to typecast.

If a typecast is required it should be specificed in the docs.

Reproduce code:
$string = <<<XML
<?xml version='1.0'?>
$xml = simplexml_load_string($string);
$login = $xml->login;
$login = (string) $xml->login;

Expected result:
SimpleXMLElement Object
    [cmd] => login
    [login] => Richard

Actual result:
SimpleXMLElement Object
    [cmd] => login
    [login] => Richard
SimpleXMLElement Object
    [0] => Richard


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-03 05:23 UTC] lists at cyberlot dot net

In trying to get this working I played with the examples from this page.

Example 7 returns the following error
Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in /root/test.php on line 29
 [2004-08-03 12:01 UTC]
That's by design and was discussed on
 [2004-08-03 15:29 UTC] lists at cyberlot dot net
Im not signed up for that list...
The online docs badly need updating then.

1. To express the need to use typecasting depending on how you access the variable.

2. That you can no longer "change" the simplexml object like explained in example 7
 [2004-08-03 15:39 UTC] lists at cyberlot dot net
Ok it is impossible to modify the simpleobject once creating which means you can't add anything to the xml.

Is this a desired affect as well?
 [2011-05-31 11:22 UTC] stu at dyndev dot co dot nz
This intentional bug is still there, I cannot for the life of me see why it would be that way or why it's still not documented all these years later.
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Sun Mar 01 00:01:49 2015 UTC