Bug #54950 [Opn->Ver]: simplexml_load_[string|file]: error_get_last is useless
| From: | cmb@php.net | Date: | Tue, 07 Aug 2018 17:32:38 +0000 |
| Subject: | Bug #54950 [Opn->Ver]: simplexml_load_[string|file]: error_get_last is useless | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-216667@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=54950&edit=1
ID: 54950
Updated by: cmb@php.net
Reported by: marc-bennewitz at arcor dot de
Summary: simplexml_load_[string|file]: error_get_last is
useless
-Status: Open
+Status: Verified
Type: Bug
Package: SimpleXML related
Operating System: Linux
PHP Version: 5.3.6
Block user comment: N
Private report: N
New Comment:
I can confirm the reported behavior: <https://3v4l.org/69E3Y>.
DOM handles this better (<https://3v4l.org/4fIVO>).
> OK 'libxml_use_internal_errors' can also be used
> but the last reported error is unhelpful anyhow
I can't confirm this: <https://3v4l.org/3eFuK>.
Previous Comments:
------------------------------------------------------------------------
[2011-05-29 19:37:11] marc-bennewitz at arcor dot de
OK 'libxml_use_internal_errors' can also be used
but the last reported error is unhelpful anyhow
------------------------------------------------------------------------
[2011-05-29 18:07:26] marc-bennewitz at arcor dot de
Description:
------------
On loading an invalid xml catched errors using error_get_last aren't helpful because the
message is nearly empty "simplexml_load_string(): ^"
It looks like there are more errors reported and the last error is the most unhelpful error but this
is the only good catchable error (see example).
A workaround only exists using an own error handler but it's nasty :(
Test script:
---------------
$xml = <<<XML
<?xml version="1.0"?>
<config>
<a>test</a>
</other>
XML;
echo 'LOAD INVALID XML STRING' . PHP_EOL;
$simpleXML = simplexml_load_string($xml);
echo 'DETECTED ERROR:' . PHP_EOL;
if ($simpleXML === false) {
$err = error_get_last();
var_dump($err);
}
Expected result:
----------------
LOAD INVALID XML STRING
PHP Warning: simplexml_load_string(): Entity: line 4: parser error : Opening and ending tag
mismatch: config line 2 and other in /tmp/bug_simpleXmlLoad.php on line 11
Warning: simplexml_load_string(): Entity: line 4: parser error : Opening and ending tag mismatch:
config line 2 and other in /tmp/bug_simpleXmlLoad.php on line 11
DETECTED ERROR:
array(4) {
["type"]=>
int(2)
["message"]=>
string(34) "simplexml_load_string(): Entity: line 4: parser error : Opening and ending tag
mismatch: config line 2 and other"
["file"]=>
string(26) "/tmp/bug_simpleXmlLoad.php"
["line"]=>
int(11)
}
Actual result:
--------------
LOAD INVALID XML STRING
PHP Warning: simplexml_load_string(): Entity: line 4: parser error : Opening and ending tag
mismatch: config line 2 and other in /tmp/bug_simpleXmlLoad.php on line 11
Warning: simplexml_load_string(): Entity: line 4: parser error : Opening and ending tag mismatch:
config line 2 and other in /tmp/bug_simpleXmlLoad.php on line 11
PHP Warning: simplexml_load_string(): </other> in /tmp/bug_simpleXmlLoad.php on line 11
Warning: simplexml_load_string(): </other> in /tmp/bug_simpleXmlLoad.php on line 11
PHP Warning: simplexml_load_string(): ^ in /tmp/bug_simpleXmlLoad.php on line 11
Warning: simplexml_load_string(): ^ in /tmp/bug_simpleXmlLoad.php on line 11
DETECTED ERROR:
array(4) {
["type"]=>
int(2)
["message"]=>
string(34) "simplexml_load_string(): ^"
["file"]=>
string(26) "/tmp/bug_simpleXmlLoad.php"
["line"]=>
int(11)
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=54950&edit=1