Home » XML » XML_Serializer » Bug #2019
defaultTagName and Arrays
Details
| Request #2019 | defaultTagName and Arrays |
|---|---|
| Submitted | 2004-07-30 00:02 UTC |
| From | djimenez at conduit-it dot com |
| Assigned | schst |
| Status | Closed |
| Package | XML_Serializer |
| PHP Version | 5.0.0 |
| OS | Windows and Linux |
| Roadmaps | (Not assigned) |
Comments
[2004-07-30 00:02 UTC] djimenez at conduit-it dot com
Description:
------------
In your Serializer you use a defaultTagName for array elements that are auto indexed by a numerical key. This is fine for data primitives in the array, but when I construct an array of objects I would prefer that the class name be used for the tag instead of the defaultTagName option. I've made the simple change (two lines) in my copy of your package, but I thought to provide this feedback in case it might be a useful permanent change to your code. I put the code inside of the typeHints if block since I'll always be using typeHints with the serializer, but the key change might be more appropriate up further in the code
Reproduce code:
---------------
From the _serializeArray(..) function in Serializer.php:
...
if ($this->options["typeHints"] === true) {
$atts[$this->options["typeAttribute"]] = gettype($value);
if ($key !== $origKey) {
$atts[$this->options["keyAttribute"]] = (string)$origKey;
}
//ADDED CODE
if(gettype($value) == 'object') {
$key = get_class($value);
}
//END ADDED CODE
}
...