Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.21.0

Bug #21052 Incompatible Attributes Options
Submitted: 2016-04-12 09:59 UTC
From: dicksonm Assigned:
Status: Open Package: XML_Serializer (version 0.20.2)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


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 : 34 + 18 = ?

 
 [2016-04-12 09:59 UTC] dicksonm (Michael Dickson)
Description: ------------ In Unserialize.php, when 'parseAttributes' is set as well as 'typeHints' the output data is corrupted by package's internal attributes. Test script: --------------- <?php $string = <<<EOD <array _type="array" Hello="world" Glad="I am"> <XML_Serializer_Tag _originalKey="To see" _type="string">You</XML_Serializer_Tag> <XML_Serializer_Tag _originalKey="I think" _type="string">We can be friends</XML_Serializer_Tag> </array> EOD; require_once 'XML/Unserializer.php'; $engine = new XML_Unserializer(); $engine->setOption('parseAttributes', true); $engine->setOption('typeHints', TRUE); $engine->unserialize($string); var_dump($engine->getUnserializedData()); ?> Expected result: ---------------- array(4) { ["Hello"]=> string(5) "world" ["Glad"]=> string(4) "I am" ["To see"]=> string(3) "You" ["I think"]=> string(17) "We can be friends" } Actual result: -------------- array(5) { ["_type"]=> string(5) "array" ["Hello"]=> string(5) "world" ["Glad"]=> string(4) "I am" [0]=> array(3) { ["_originalKey"]=> string(6) "To see" ["_type"]=> string(6) "string" ["_content"]=> string(3) "You" } [1]=> array(3) { ["_originalKey"]=> string(7) "I think" ["_type"]=> string(6) "string" ["_content"]=> string(17) "We can be friends" } }

Comments

 [2016-04-12 10:05 UTC] dicksonm (Michael Dickson)
 [2016-04-12 10:09 UTC] dicksonm (Michael Dickson)
I found the above patch solves the problem by creating a $dataAttribs which does not contain the internal attributes _originalKey, _type, or _class.
 [2016-07-19 15:11 UTC] dicksonm (Michael Dickson)
There's a connected issue regarding array serialization. If we run: <?php $array = array( array('data' => 'world'), array('data' => 'hello'), ); require_once 'XML/Serializer.php'; require_once 'XML/Unserializer.php'; $S = new XML_Serializer(); $U = new XML_Unserializer(); $S->serialize($array); $U->unserialize($S->getSerializedData()); var_dump($U->getUnserializedData()); ?> We end up with: array(1) { ["XML_Serializer_Tag"]=> array(2) { [0]=> array(1) { ["data"]=> string(5) "world" } [1]=> array(1) { ["data"]=> string(5) "hello" } } } To avoid this, we set $U->setOption('ignoreKeys', array('XML_Serializer_Tag')); The test then returns the original input, as expected: array(2) { [0]=> array(1) { ["data"]=> string(5) "world" } [1]=> array(1) { ["data"]=> string(5) "hello" } } However, this fails when the test data contains non-numeric indices: <?php $array = array( 'first line' => array('data' => 'world'), 'second line' => array('data' => 'hello'), ); ?> Output remains as though numeric indices were used.
 [2016-07-19 15:13 UTC] dicksonm (Michael Dickson)