#35028 [Csd]: XML object fails FALSE test
| From: | helly@php.net | Date: | Tue, 29 Nov 2005 03:23:43 +0000 |
| Subject: | #35028 [Csd]: XML object fails FALSE test | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-89347@lists.php.net to get a copy of this message | ||
ID: 35028
Updated by: helly@php.net
Reported By: lists at cyberlot dot net
Status: Closed
Bug Type: SimpleXML related
Operating System: *
PHP Version: 5.1.1
Assigned To: helly
New Comment:
Actually if that was wanted it is wrong. The function call returns a
SimpleXML object. And that object is then converted to a boolean value.
If you want to check whether the function call was successfulll then
check if the return value is an object or the other way round $xml ===
null.
Previous Comments:
------------------------------------------------------------------------
[2005-11-29 03:51:12] helly@php.net
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
------------------------------------------------------------------------
[2005-11-28 13:36:54] shuyg at roadside dot nl
if ($test = simplexml_load_string($xml))
...
In php 5.1.0 this will return False (always). In 5.0.5 it returns True
when it succesfully parsed $xml.
I guess that this is what "lists at cyberlot dot net" realy wants.
------------------------------------------------------------------------
[2005-10-30 21:45:42] helly@php.net
For 5.1.0 you'd need to use isset() instead of plain if() test since we
are too far in release process to have a big changes in it. But i will
do just after 5.1.0 is out the doors. Also it is fixed in HEAD.
Anyway i tried it with 5.0.6-dev and am nearly sure it does not work in
any version yet.
Btw, a boolean if() for normal php objects is a check whether the
object has any properties. This is probably not what you want. After
the change it results in true whenever there are sub elements,
attributes or a selected node.
------------------------------------------------------------------------
[2005-10-30 19:29:44] alex at whitewhale dot net
Note that if you change $string to:
$string = str_replace('><','>
<',"<doc><login>kkl</
login><password>klk</password></doc>");
It passes.
------------------------------------------------------------------------
[2005-10-30 19:21:46] lists at cyberlot dot net
Description:
------------
$xml object returns false, this worked in RC1 fails in RC3 and RC4
never tested RC2
xml string of <doc>test</doc> DOES pass test. Its only when you have
subchildren children that the $xml object fails to pass.
<doc><test>test</test></doc> fails
<doc>test</doc> Passes.
if(is_object($xml)) { works, and is prob the best method to use but one
would expect $xml to be "true"
Realize this might be considered a dupe of bug #31045 however bug
#34199 suggests the same issue that states this is fixed.
Reproduce code:
---------------
<?
$string =
"<doc><login>kkl</login><password>klk</password></doc>";
$xml = simplexml_load_String($string);
if($xml) {
echo "Passed test\n";
} else {
echo "Even though is object still failed false test\n";
}
?>
Expected result:
----------------
Expect output of Passed test
Actual result:
--------------
output of Even though is object still failed false test
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=35028&edit=1