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

Request #13564 bool(false) is converted to empty string
Submitted: 2008-04-02 13:38 UTC
From: naag Assigned: ashnazg
Status: Closed Package: XML_Serializer (version 0.18.0)
PHP Version: 5.2.4 OS: Ubuntu 8.04
Roadmaps: 0.20.0    
Subscription  


 [2008-04-02 13:38 UTC] naag (Peter Bücker)
Description: ------------ XML_Serializer converts all values which are not objects or arrays to strings using "@settype($data, 'string');". This leads to bool(false) being converted to an empty string, while bool(true) is converted to the integer 1. In some applications which require a stricter definition of true and false, this breaks things. I would rather like to see XML_Serializer make bool(false) a special case and convert it to integer 0, which also seems more consistent. I think that the XML output from XML_Serializer should be programming language independent and should thus avoid PHP-idiosyncrasies. A patch which fixes the problem for me is attached. Test script: --------------- <?php require('XML/Serializer.php'); $serializer = new XML_Serializer(); $serializer->setOption('rootName', 'BooleanTest'); if ($serializer->serialize(false)) { var_dump($serializer->getSerializedData()); } if ($serializer->serialize(true)) { var_dump($serializer->getSerializedData()); } Expected result: ---------------- string(28) "<BooleanTest>0</BooleanTest>" string(28) "<BooleanTest>1</BooleanTest>" Actual result: -------------- string(15) "<BooleanTest />" string(28) "<BooleanTest>1</BooleanTest>"

Comments

 [2008-09-19 20:02 UTC] ashnazg (Chuck Burgess)
Building from Peter's original patch, I've implemented a new runtime option XML_SERIALIZER_OPTION_FALSE_AS_STRING, which defaults to FALSE (providing current functionality), with set to TRUE generating the requested new functionality. Will see about adding this in 0.20.0 release.
 [2008-09-19 20:43 UTC] ashnazg (Chuck Burgess)
Moving to Feedback, to solicit any feedback on my plan while waiting for other changes for 0.19.1 to be committed (can't commit this until after those).
 [2008-10-26 19:07 UTC] naag (Peter Bücker)
Thank you chuck, a runtime option for this is the best way to fix it. I will be happy so see this in a future release!
 [2009-06-01 23:36 UTC] ashnazg (Chuck Burgess)
-Status: Assigned +Status: Analyzed
 [2009-06-12 08:17 UTC] ashnazg (Chuck Burgess)
-Status: Analyzed +Status: Assigned -Assigned To: +Assigned To: ashnazg
Implementation committed to CVS... will be included in release 0.20.0.
 [2009-06-12 08:17 UTC] ashnazg (Chuck Burgess)
-Status: Assigned +Status: Closed