#49251 [Ver->Bgs]: wrong object created
| From: | rrichards@php.net | Date: | Fri, 25 Sep 2009 18:32:14 +0000 |
| Subject: | #49251 [Ver->Bgs]: wrong object created | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-142888@lists.php.net to get a copy of this message | ||
ID: 49251
Updated by: rrichards@php.net
Reported By: ies_clan at hotmail dot com
-Status: Verified
+Status: Bogus
Bug Type: SimpleXML related
Operating System: *
PHP Version: 5.*, 6 (2009-08-17)
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
simpleXML returns simpleXML objects when accessing properties of the
document, and calling new on the returned object, creates a new object
of that type returned.
You need to cast to string before calling new, i.e.:
$mclass = (string)$Xml->classname;
$XmlClass = new $mclass('<root />');
Previous Comments:
------------------------------------------------------------------------
[2009-08-17 18:22:32] jani@php.net
And it only happens with 'new'.
------------------------------------------------------------------------
[2009-08-17 18:19:09] jani@php.net
Quite weird indeed. And verified in all branches.
------------------------------------------------------------------------
[2009-08-14 13:49:22] ies_clan at hotmail dot com
Description:
------------
if u try to create a new object from an simple xml-objekt-property you
got an simple xml object :(
Reproduce code:
---------------
class test {}
$Xml = new
SimpleXMLElement('<root><classname>stdclass</classname></root>');
$XmlClass = new $Xml->classname('<root />');
print_r($XmlClass);
$MyClass = new stdclass();
$MyClass->classname = 'test';
$stdclass = new $MyClass->classname();
print_r($stdclass);
Expected result:
----------------
stdclass Object
(
)
test Object
(
)
Actual result:
--------------
SimpleXMLElement Object
(
)
test Object
(
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49251&edit=1