php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44266 classes inheriting from SimpleXMLElement cannot have properties
Submitted: 2008-02-27 14:07 UTC Modified: 2008-03-14 19:03 UTC
Votes:4
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:0 (0.0%)
From: m dot beyer5 at gmx dot de Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: * OS: *
Private report: No CVE-ID: None
 [2008-02-27 14:07 UTC] m dot beyer5 at gmx dot de
Description:
------------
Classes inheriting from SimpleXMLElements should be able to have class properties the same way any other class does.
Currently SimpleXML treats operations on class properties as operations on the xml part of the object.
There should be a way to adress both seperately.

Reproduce code:
---------------
      class Foo extends SimpleXMLElement
      {
            public $bar;
      }
      
      $str = "<xml></xml>";
      
      $foo = new Foo($str);
      $foo->bar = array();

Expected result:
----------------
Assigning anything to Foo->bar should not affect the XML part but should be handled as a normal class property.

Actual result:
--------------
SimpleXMLElement tries to interpret the public variable as an XML Element, causing a warning:

Warning: It is not yet possible to assign complex types to properties

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-14 19:03 UTC] helly@php.net
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

Short answer no.

SimpleXML is designed in a way that properties map to sub elements or attributes depending on the current level. So we cannot have some of those mapping to pure properties. What you want is wrapping SimpleXML instances in your own class (has-a design).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 01 21:01:32 2024 UTC