go to bug id or search bugs for
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.
$xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<ns1:Node>There's stuff here</ns1:Node>
$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;
There's stuff here
There's stuff here
Add a Patch
Add a Pull Request
Related to bug #30972, bug #31045 and to user note #117237.
The following patch has been added/updated:
Patch Name: simplexml-false-problem
Automatic comment from SVN on behalf of cmb
Log: added return.falseproblem warning to SimpleXML factory functions (fixes bug #69596)
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
Thank you for the report, and for helping us make PHP better.
Disregard the comment above (wrong snippet).
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation better.