|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-05-29 19:37 UTC] marc-bennewitz at arcor dot de
[2018-08-07 17:32 UTC] cmb@php.net
-Status: Open
+Status: Verified
[2018-08-07 17:32 UTC] cmb@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 02:00:01 2025 UTC |
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) }