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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 03:01:29 2024 UTC