|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #69596 simplexml_load_string can return SimpleXML object that resolves to FALSE
Submitted: 2015-05-07 15:33 UTC Modified: 2015-06-14 14:08 UTC
From: meustrus at gmail dot com Assigned: cmb (profile)
Status: Closed Package: SimpleXML related
PHP Version: Irrelevant OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: meustrus at gmail dot com
New email:
PHP Version: OS:


 [2015-05-07 15:33 UTC] meustrus at gmail dot com
From manual page:

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:

$xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<ns1:Root xmlns:ns1="">
<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('')->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


simplexml-false-problem (last revision 2015-05-07 22:46 UTC by

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-07 22:32 UTC]
-PHP Version: 5.4.40 +PHP Version: Irrelevant
 [2015-05-07 22:33 UTC]
-Status: Open +Status: Verified -Operating System: OS X +Operating System: *
 [2015-05-07 22:33 UTC]
Verified: <>.
 [2015-05-07 22:38 UTC]
Related to bug #30972, bug #31045 and to user note #117237.
 [2015-05-07 22:46 UTC]
The following patch has been added/updated:

Patch Name: simplexml-false-problem
Revision:   1431038794
 [2015-06-14 14:06 UTC]
Automatic comment from SVN on behalf of cmb
Log: added return.falseproblem warning to SimpleXML factory functions (fixes bug #69596)
 [2015-06-14 14:07 UTC]
-Status: Verified +Status: Closed -Assigned To: +Assigned To: cmb
 [2015-06-14 14:07 UTC]
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

 For Windows:
Thank you for the report, and for helping us make PHP better.

 [2015-06-14 14:08 UTC]
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.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 25 13:01:28 2024 UTC