#46122 [Opn->Fbk]: Simplexmlelement typecasts right to string and int but not to bool
| From: | jani@php.net | Date: | Sun, 26 Oct 2008 11:18:35 +0000 |
| Subject: | #46122 [Opn->Fbk]: Simplexmlelement typecasts right to string and int but not to bool | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-130124@lists.php.net to get a copy of this message | ||
ID: 46122
Updated by: jani@php.net
Reported By: dirk at heilig-online dot com
-Status: Open
+Status: Feedback
Bug Type: SimpleXML related
Operating System: Debian
PHP Version: 5.2.6
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
Previous Comments:
------------------------------------------------------------------------
[2008-09-19 12:23:26] dirk at heilig-online dot com
Description:
------------
Simplexmlelement->node auto-typecasts right to int or string but a
typecast to bool does the same thing as is_set().
to check if a node contains a true or a false value you have to check
(bool)(string)$simplexmlelement->node.
Reproduce code:
---------------
<?php
$xmlstring="
<xml>
<node>0</node>
</xml>";
$xmlelement=new SimpleXMLElement($xmlstring);
echo "(int)element: ";
var_dump((int)$xmlelement->node);
echo "--\n";
echo "(bool)element: ";
var_dump((bool)$xmlelement->node);
echo "--\n";
echo "(bool)(string)element: ";
var_dump((bool)(string)$xmlelement->node);
Expected result:
----------------
(int)element: int(0)
--
(bool)element: bool(false)
--
(bool)(string)element: bool(false)
Actual result:
--------------
(int)element: int(0)
--
(bool)element: bool(true)
--
(bool)(string)element: bool(false)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46122&edit=1