|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25264 XML_Unserializer doesn't support element attributes
Submitted: 2003-08-26 16:58 UTC Modified: 2003-09-11 11:34 UTC
From: marshall at exclupen dot com Assigned: schst (profile)
Status: Closed Package: PEAR related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2003-08-26 16:58 UTC] marshall at exclupen dot com
XML_Unserializer works great for turning an XML file into an array, but I can't figure out how to get attributes.

Here's a hypothetical example using as a base:

    [channel] => Array
            [language] => en
            [image] => Array
                    [url] =>
                    [link] =>


Now, I know this would be against the RSS spec (I just needed an example XML file), but what if "image" had width and height attributes?

[image] => Array
        [url] =>
        [link] =>
        [attr_width] => 104
        [attr_height] => 50

All is well and good there.  Now imagine that "link" has a "title" attribute:

[image] => Array
        [url] =>
        [link] => Array
                [0] =>
                [attr_title] => PEAR

Suddenly, "link" has changed from a string to an array.  If the attributes are optional, you could never be sure which it would be. The 0 is used as a key to avoid naming conflicts that could come up with "content" or "data".

One solution would be to make every value an array.  Strings would become arrays with only 1 element (key 0).

Reproduce code:
require_once 'XML/Unserializer.php';
$options = array('complexType' => 'array');
$unserializer = &new XML_Unserializer($options);

$unserializer->unserialize('', true);    

$rss = $unserializer->getUnserializedData();
echo "<pre>";
echo "</pre>";


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-27 02:18 UTC]
I will add a feature to unserialize tags with attributes in the next release, currently working on it.
 [2003-08-27 04:02 UTC]
changed email address back, /me is stupid

BTW: This is not bug, just a feature request.
 [2003-09-11 11:34 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

This has been added for the current CVS version. There are sveral ways of reading XML with attributes, as well as writing attributes. Will be included in the next release.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Aug 05 02:01:23 2021 UTC