Bug #29500 [Com]: Accessing object elements returns object

From: Date: Sun, 22 Mar 2015 02:07:29 +0000
Subject: Bug #29500 [Com]: Accessing object elements returns object
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191517@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=29500&edit=1 ID: 29500 Comment by: perske at uni-muenster dot de Reported by: lists at cyberlot dot net Summary: Accessing object elements returns object Status: Wont fix Type: Bug Package: SimpleXML related Operating System: Fedora Core 2 PHP Version: 5.0.0 Block user comment: N Private report: N New Comment: This behaviour *is* documented, but at a very hidden place: On the lengthy page http://php.net/manual/en/simplexml.examples-basic.php in the introduction to example #6. The bug is not the need for a cast; this need is technically well-founded, see the internal discussions. The bug is using the word "simple" in the name of a class with an interface that looks so absurd to the eyes of the usual programmer. But it is to late to fix this bug. If you dislike casts, you can access elements and attributes without using them: $login = $xml->login->__toString(); But (string)$xml->login and "{$xml->login}" are shorter. Previous Comments: ------------------------------------------------------------------------ [2011-05-31 11:22:09] 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. ------------------------------------------------------------------------ [2004-08-03 15:39:41] 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? ------------------------------------------------------------------------ [2004-08-03 15:29:03] 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 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 ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=29500 -- Edit this bug report at https://bugs.php.net/bug.php?id=29500&edit=1

« previous php.bugs (#191517) next »