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

 ID:                 52482
 Updated by:         sala...@php.net
 Reported by:        sjon at react dot com
 Summary:            Casting SimpleXMLElement('0') to boolean results in
                     true
 Status:             Open
 Type:               Feature/Change Request
 Package:            SimpleXML related
 Operating System:   Linux
 PHP Version:        Irrelevant
 Block user comment: N

 New Comment:

You are not casting the string "0" to boolean, you're casting the
object. As such, 

it follows normal rules for casting objects. The only time a
SimpleXMLElement will 

cast to boolean false is with an "empty" element (e.g. "<w/>").



If you want your sample element to cast to false, you will first need to
cast to a 

string: (bool) (string) new SimpleXMLElement...


Previous Comments:
------------------------------------------------------------------------
[2010-07-29 10:50:11] sjon at react dot com

Description:
------------
I understand the bug I am reporting is described in the manual, which is
why I am reporting it as a feature request. When casting
SimpleXMLElements to boolean, most values comply with the way PHP casts
them. There is however one exception: the string '0' is cast to true,
which is unexpected. This is especially annoying when using XmlRpc,
which uses <boolean>0</boolean> for its values.

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



var_dump((bool)new SimpleXMLElement("<w>0</w>"));

Expected result:
----------------
bool(false)

Actual result:
--------------
bool(true)


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



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

Reply via email to