Bug #73670 [NEW]: simplexml_load_string returns `FALSE` but does not set error (for empty strings
| From: | zerkms at zerkms dot ru | Date: | Wed, 07 Dec 2016 01:18:44 +0000 |
| Subject: | Bug #73670 [NEW]: simplexml_load_string returns `FALSE` but does not set error (for empty strings | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-205814@lists.php.net to get a copy of this message | ||
From: zerkms at zerkms dot ru
Operating system: Irrelevant
PHP version: Irrelevant
Package: SimpleXML related
Bug Type: Bug
Bug description:simplexml_load_string returns
FALSE but does not set error (for empty
strings
Description:
------------
simplexml_load_string() documentation states
> Returns an object of class SimpleXMLElement with properties containing
the data held within the xml document, or FALSE on failure.
So I expect if FALSE is returned - it was failed to parse xml, so the
libxml_get_last_error returns the actual error.
What happens instead - for the empty string the simplexml_load_string
returns false and libxml_get_last_error returns previous non actual
error.
It should be either a documentation additionally clarify the case, or
the implementation behave accordingly.
Test script:
---------------
$previous = libxml_use_internal_errors(true);
$doc = simplexml_load_string('foo');
libxml_use_internal_errors($previous);
$result = libxml_get_last_error();
$previous = libxml_use_internal_errors(true);
$doc = simplexml_load_string('');
libxml_use_internal_errors($previous);
$result = libxml_get_last_error();
var_dump($doc, $result);
Expected result:
----------------
bool(false)
bool(false)
Actual result:
--------------
bool(false)
object(LibXMLError)#2 (6) {
["level"]=>
int(3)
["code"]=>
int(4)
["column"]=>
int(1)
["message"]=>
string(34) "Start tag expected, '<' not found
"
["file"]=>
string(0) ""
["line"]=>
int(1)
}
--
Edit bug report at https://bugs.php.net/bug.php?id=73670&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73670&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73670&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73670&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73670&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73670&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73670&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73670&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73670&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73670&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73670&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73670&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73670&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73670&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73670&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73670&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73670&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73670&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73670&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73670&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73670&r=mysqlcfg