PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » XML » XML_Serializer » Bug #3303

Cannot tell Unserializer not to use tag names for class

Details

Submitted2005-01-26 17:30 UTC
Fromscarpenter at allofe dot net
Assignedschst
StatusClosed
PackageXML_Serializer
PHP Version4.3.9
OSRedhat 8.0
Roadmaps(Not assigned)

Comments

[2005-01-26 17:30 UTC] scarpenter at allofe dot net

Description:
------------
When using the option 'complexType' => 'object' the Unserialize will use the tag name for the class that is created from the data if the class exists. This is a cool feature. Problem is it can't be turned off and often tag names match preexisting classes that require arguments in their constructor thus causing a warning. An option to specify that stdClass is always used would make it possible to prevent this problem. Since this is prone to result in a warning at random(depending on the xml) perhaps it shouldn't even be the default behavior.

Reproduce code:
---------------
<?
class state {
var $arg1;
function state($arg1) {
$this->arg1 = $arg1;
}
}
$xml_str = '<data><states><state><id>1</id></state><state><id>2</id></state></states></data>';
require_once 'XML/Unserializer.php';
$unserializer = new XML_Unserializer(array('parseAttributes'=>false, 'complexType'=>'object'));
$status = $unserializer->unserialize($xml_str, $is_file=false);
$data = $unserializer->getUnserializedData();
print_r($data);
?>

Expected result:
----------------
stdClass Object
(
[states] => stdClass Object
(
[state] => Array
(
[0] => stdClass Object
(
[id] => 1
)

[1] => stdClass Object
(
[id] => 2
)

)

)

)

Actual result:
--------------
<br />
<b>Warning</b>: Missing argument 1 for state() in <b>/xdisk/devel/active/contentm_v2/scarpenter/wf_instances/wf_test.php</b> on line <b>4</b><br />
<br />
<b>Warning</b>: Missing argument 1 for state() in <b>/xdisk/devel/active/contentm_v2/scarpenter/wf_instances/wf_test.php</b> on line <b>4</b><br />
stdClass Object
(
[states] => stdClass Object
(
[state] => Array
(
[0] => state Object
(
[arg1] =>
[id] => 1
)

[1] => state Object
(
[arg1] =>
[id] => 2
)

)

)

)