PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » XML » XML_Serializer » Bug #4325

Can't serialize an array with multiple identical keys

Details

Submitted2005-05-11 07:23 UTC
Fromconsulting at jtroiano dot com
StatusBogus
PackageXML_Serializer
PHP Version4.3.7
OSLinux 2.4.25-ow1
Roadmaps(Not assigned)

Comments

[2005-05-11 07:23 UTC] consulting at jtroiano dot com

Description:
------------
PEAR.php,v 1.80
Serializer.php,v 1.34
Util.php,v 1.24

When attempting to serialize an associative array
containing multiple keys of the same name (in this case
'field'), only the last key/value pair is returned as an
XML element.

Reproduce code:
---------------
$this->_xmlQuery = array(
"requestby" => array(
"office" => "OfficeID",
"branch" => "BranchID",
"webid" => "WebID",
"password" => "Password"
),
"query" => array(
"querytype" => "customfieldlistbywhere",
"querydata" => "SQL WHERE clause",
"fieldlist" => array(
"field" => "cl_class",
"field" => "mls_num",
"field" => "lp_list_price",
"field" => "sf_square_feet"
)
)
);
$result = $serializer->serialize($this->_xmlQuery);

Expected result:
----------------
Expected to have multiple <field> elements as children
to the <fieldlist> element. The <field> elements tell
the database server the exact subset of data to return
in reponse to the request.

FWIW, I tried tweaking the loop structures w/in
_serializeArray() myself, to no avail. Wound up hand-
coding the XML for the contents of <fieldlist>, setting
replaceEntities to XML_SERIALIZER_ENTITIES_NONE, and
calling htmlspecialchars() on the string passed into
<querydata> - as a work-around. It works fine that way.

The package itself has greatly simplified my task.
Thanks for the good work.

Actual result:
--------------
<fieldlist><field>sf_square_feet</field></fieldlist>

[2005-05-11 22:22 UTC] consulting at jtroiano dot com

Ah, I see. Each assignment was overwriting the
previous. I guess my "work-around" is actually the only
way to build such a structure from an array.

Sorry for wasting your time.