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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
49 - 2 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Fri Apr 26 09:01:29 2024 UTC