php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52889 Getting a SimpleXMLElement tree with differents objects as nodes
Submitted: 2010-09-19 19:13 UTC Modified: -
From: ivan dot enderlin at hoa-project dot net Assigned:
Status: Open Package: SimpleXML related
PHP Version: Irrelevant OS:
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: ivan dot enderlin at hoa-project dot net
New email:
PHP Version: OS:

 

 [2010-09-19 19:13 UTC] ivan dot enderlin at hoa-project dot net
Description:
------------
Now, it is not possible to get different objects that inherit from SimpleXMLElement as nodes of the SimpleXML tree. We get a warning with the message "It is not yet possible to assign complex types to properties", but it is not a complex types: it is a child of SimpleXMLElement. Maybe, we can avoid the warning of assigning unknown object if this object inherits from SimpleXMLElement? It could save a lot of time for interpreting a SimpleXML tree.

Test script:
---------------
<?php

$xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n" .
       '<handler>' . "\n" .
       '  <foo>' . "\n" .
       '    <bar>baz</bar>' . "\n" .
       '  </foo>' . "\n" .
       '  <foo>' . "\n" .
       '    <bar>qux</bar>' . "\n" .
       '  </foo>' . "\n" .
       '</handler>';

class A extends SimpleXMLElement { }
class B extends SimpleXMLElement { }

$sxe = simplexml_load_string($xml, 'A');

$sxe->foo[0] = simplexml_import_dom(
    dom_import_simplexml($sxe->foo[0]),
    'B'
);

print_r($sxe);

Expected result:
----------------
A Object
(
    [foo] => Array
        (
            [0] => ___B___ Object
                (
                    [bar] => baz
                )

            [1] => A Object
                (
                    [bar] => qux
                )

        )

)

Actual result:
--------------
Warning: It is not yet possible to assign complex types to properties in ... on line 18
A Object
(
    [foo] => Array
        (
            [0] => A Object
                (
                    [bar] => baz
                )

            [1] => A Object
                (
                    [bar] => qux
                )

        )

)

Patches

Pull Requests

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 08 15:01:28 2024 UTC