Doc #69596 [Ver->Csd]: simplexml_load_string can return SimpleXML object that resolves to FALSE
| From: | cmb@php.net | Date: | Sun, 14 Jun 2015 14:07:03 +0000 |
| Subject: | Doc #69596 [Ver->Csd]: simplexml_load_string can return SimpleXML object that resolves to FALSE | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-12416@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69596&edit=1
ID: 69596
Updated by: cmb@php.net
Reported by: meustrus at gmail dot com
Summary: simplexml_load_string can return SimpleXML object
that resolves to FALSE
-Status: Verified
+Status: Closed
Type: Documentation Problem
Package: SimpleXML related
Operating System: *
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
The fix for this bug has been committed.
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/.
For Windows:
http://windows.php.net/snapshots/
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2015-06-14 14:06:15] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=336942
Log: added return.falseproblem warning to SimpleXML factory functions (fixes bug #69596)
------------------------------------------------------------------------
[2015-05-07 22:46:34] cmb@php.net
The following patch has been added/updated:
Patch Name: simplexml-false-problem
Revision: 1431038794
URL: https://bugs.php.net/patch-display.php?bug=69596&patch=simplexml-false-problem&revision=1431038794
------------------------------------------------------------------------
[2015-05-07 22:38:46] cmb@php.net
Related to bug #30972, bug #31045 and to user note #117237.
------------------------------------------------------------------------
[2015-05-07 22:33:14] cmb@php.net
Verified: <http://3v4l.org/uUUDH>.
------------------------------------------------------------------------
[2015-05-07 15:33:14] meustrus at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=69596&edit=1