Edit report at http://bugs.php.net/bug.php?id=53406&edit=1

 ID:                 53406
 Updated by:         cataphr...@php.net
 Reported by:        dubois dot benjamin at me dot com
 Summary:            inconsistent behavior with booleans in
                     writeElement() method
-Status:             Open
+Status:             Bogus
 Type:               Bug
 Package:            XML Writer
 Operating System:   ANY
 PHP Version:        5.3.3
 Block user comment: N
 Private report:     N

 New Comment:

This is not inconsistent, it follows the general rules used for boolean
-> string conversions in PHP:



>php -r "echo false, \"\ndone\";"



done

>php -r "echo true, \"\ndone\";"



1

done


Previous Comments:
------------------------------------------------------------------------
[2010-11-25 20:22:51] dubois dot benjamin at me dot com

Description:
------------
I use xmlWriter a lot, but I found a quite inconsistent behavior with
booleans in 

xmlWriter. 



When filling an element/namespace with a boolean : 



- if the boolean is true, it is automatically casted to an int (1),
which is a 

legal representation of the boolean. 

- if the boolean is false, no value is given to the element/attribute. 



I made a little script to reproduce the problem.It runs well in CLI

Test script:
---------------
<?php



xml(true);

xml(false);



function xml($bool) {

        $xml = new XmlWriter();

        $xml->openMemory();

        $xml->setIndent(true);

        $xml->startElement('root');

        $xml->writeAttribute('boolAttr', $bool);

        $res = $xml->writeElement('myboolean',$bool);

        $xml->endElement();

        echo $xml->flush().PHP_EOL;

        var_dump($res);

}

Expected result:
----------------
<root boolAttr="1">

 <myboolean>1</myboolean>

</root>



bool(true)

<root boolAttr="0">

 <myboolean>0</myboolean>

</root>

Actual result:
--------------
<root boolAttr="1">

 <myboolean>1</myboolean>

</root>



bool(true)

<root boolAttr="">

 <myboolean></myboolean>

</root>


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=53406&edit=1

Reply via email to