php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46122 Simplexmlelement typecasts right to string and int but not to bool
Submitted: 2008-09-19 12:23 UTC Modified: 2008-11-03 01:00 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: dirk at heilig-online dot com Assigned:
Status: No Feedback Package: SimpleXML related
PHP Version: 5.2.6 OS: Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
50 - 5 = ?
Subscribe to this entry?

 
 [2008-09-19 12:23 UTC] 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)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-26 11:18 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2008-11-03 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 15:01:29 2024 UTC