Bug #53406 [NEW]: inconsistent behavior with booleans in writeElement() method
| From: | dubois dot benjamin at me dot com | Date: | Thu, 25 Nov 2010 19:22:55 +0000 |
| Subject: | Bug #53406 [NEW]: inconsistent behavior with booleans in writeElement() method | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-156449@lists.php.net to get a copy of this message | ||
From:
Operating system: ANY
PHP version: 5.3.3
Package: XML Writer
Bug Type: Bug
Bug description:inconsistent behavior with booleans in writeElement() method
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 bug report at http://bugs.php.net/bug.php?id=53406&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53406&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53406&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53406&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=53406&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53406&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=53406&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=53406&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=53406&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=53406&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=53406&r=support
Expected behavior: http://bugs.php.net/fix.php?id=53406&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=53406&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=53406&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=53406&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53406&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=53406&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=53406&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=53406&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=53406&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=53406&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=53406&r=mysqlcfg