Doc #69596 [NEW]: simplexml_load_string can return SimpleXML object that resolves to FALSE

From: Date: Thu, 07 May 2015 15:33:15 +0000
Subject: Doc #69596 [NEW]: simplexml_load_string can return SimpleXML object that resolves to FALSE
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-12304@lists.php.net to get a copy of this message
From: meustrus at gmail dot com Operating system: OS X PHP version: 5.4.40 Package: SimpleXML related Bug Type: Documentation Problem Bug description:simplexml_load_string can return SimpleXML object that resolves to FALSE Description: ------------ --- From manual page: http://www.php.net/function.simplexml-load-string --- The simplexml_load_string function returns a SimpleXML object or FALSE. However under certain conditions it may return a SimpleXML object that resolves as FALSE, complicating error handling. Spcifically, this happens when all elements in the document are namespaced, resulting in no publicly visible state in the SimpleXML object. The documentation should be updated with a warning similar to that for strpos that when checking for failure, the output must be compared to FALSE with === instead of simply resolved using PHP's casting rules. Test script: --------------- <?php $xml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <ns1:Root xmlns:ns1="http://example.com/custom"> <ns1:Node>There's stuff here</ns1:Node> </ns1:Root> XML; $simplexml = simplexml_load_string($xml); // This prints "Parse Error". echo ($simplexml ? 'Valid XML' : 'Parse Error'), PHP_EOL; // But this prints "There's stuff here", proving that // the SimpleXML object was created successfully. echo $simplexml->children('http://example.com/custom')->Node, PHP_EOL; // The documentation should instruct us to use this instead: echo ($simplexml !== FALSE ? 'Valid XML' : 'Parse Error'), PHP_EOL; Expected result: ---------------- Valid XML There's stuff here Valid XML Actual result: -------------- Parse Error There's stuff here Valid XML -- Edit bug report at https://bugs.php.net/bug.php?id=69596&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69596&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69596&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69596&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69596&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69596&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69596&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69596&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69596&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69596&r=support Expected behavior: https://bugs.php.net/fix.php?id=69596&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69596&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69596&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69596&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69596&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69596&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69596&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69596&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69596&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69596&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69596&r=mysqlcfg

« previous php.doc.bugs (#12304) next »