php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35028 SimpleXML object fails FALSE test
Submitted: 2005-10-30 19:21 UTC Modified: 2005-11-29 09:15 UTC
From: lists at cyberlot dot net Assigned: helly (profile)
Status: Closed Package: SimpleXML related
PHP Version: 5.1.1 OS: *
Private report: No CVE-ID: None
 [2005-10-30 19:21 UTC] 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



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-30 19:29 UTC] 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 21:45 UTC] 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-11-28 13:36 UTC] 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-11-29 03:51 UTC] 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-29 04:23 UTC] helly@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC