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

Bug #3885 unserializing indexed arrays with one element
Submitted: 2005-03-19 08:47 UTC Modified: 2006-12-27 00:10 UTC
From: gabest at gabest dot org Assigned:
Status: Bogus Package: XML_Serializer
PHP Version: 4.3.2 OS:
Roadmaps: (Not assigned)    
Subscription  


 [2005-03-19 08:47 UTC] gabest at gabest dot org
Description: ------------ I think this isn't really a bug, but rather something fudamentally wrong (maybe with my approach to the problem). Let's say I have the following xml structure as a string: <root> <node> <item><name>apple</name></item> </node> <node> <item><name>orange</name></item> <item><name>banana</name></item> </node> </root> Then I try to unserialize this into a php array to display the item names with smarty. The problem is, it ends up in such an ambigous structure: Array ( [node] => Array ( [0] => Array ( [item] => Array ( [name] => apple ) ) [1] => Array ( [item] => Array ( [0] => Array ( [name] => orange ) [1] => Array ( [name] => banana ) ) ) ) ) Now, if I wanted to iterate this with smarty I'd need to write something like this ... {foreach from=$node key=nindex item=n} node {$nindex}<br> {foreach from=$n.item key=index item=i} {$index} => {$i.name}<br> {/foreach} {/foreach} .. which would print this ... node 0 name => a node 1 0 => orange 1 => banana ... not exactly what I wished for. Any idea how to avoid this situation? Is there a magic option to tell the unserializer what tags to treat as indexed arrays?

Comments

 [2005-03-19 09:34 UTC] gabest at gabest dot org
Sorry, just stepped though the debugger and noticed it was the forceEnum option I needed. Would be nice to have a documentation on these things at least :)
 [2005-03-19 20:20 UTC] schst
Feel free to contribute to the documentation :) There should be an example that uses this option... Stephan
 [2005-03-20 12:55 UTC] schst
This option already is documented. Did you take a look at http://pear.php.net/manual/en/package.xml.xml-serializer.xml-unserializer.options.php ?
 [2005-03-20 13:06 UTC] gabest at gabest dot org
True... My mistake not noticing it!
 [2006-12-27 00:10 UTC] cellog (Greg Beaver)
bogus