#29500 [WFx]: Accessing object elements returns object

From: Date: Tue, 03 Aug 2004 13:29:04 +0000
Subject: #29500 [WFx]: Accessing object elements returns object
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-64018@lists.php.net to get a copy of this message
ID: 29500 User updated by: lists at cyberlot dot net Reported By: lists at cyberlot dot net Status: Wont fix Bug Type: SimpleXML related Operating System: Fedora Core 2 PHP Version: 5.0.0 New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2004-08-03 12:01:13] chregu@php.net That's by design and was discussed on internals@lists.php.net ------------------------------------------------------------------------ [2004-08-03 05:23:22] lists at cyberlot dot net http://us3.php.net/manual/en/ref.simplexml.php 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 05:15:42] lists at cyberlot dot net Description: ------------ 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'?> <document> <cmd>login</cmd> <login>Richard</login> </document> XML; $xml = simplexml_load_string($string); print_r($xml); $login = $xml->login; print_r($login); $login = (string) $xml->login; print_r($login); Expected result: ---------------- SimpleXMLElement Object ( [cmd] => login [login] => Richard ) Richard Richard Actual result: -------------- SimpleXMLElement Object ( [cmd] => login [login] => Richard ) SimpleXMLElement Object ( [0] => Richard ) Richard ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29500&edit=1

« previous php.bugs (#64018) next »