From: Operating system: Linux PHP version: 5.3.6 Package: SimpleXML related Bug Type: Bug Bug description:simplexml_load_[string|file]: error_get_last is useless
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 bug report at http://bugs.php.net/bug.php?id=54950&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54950&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54950&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54950&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=54950&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54950&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=54950&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=54950&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=54950&r=needscript Try newer version: http://bugs.php.net/fix.php?id=54950&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=54950&r=support Expected behavior: http://bugs.php.net/fix.php?id=54950&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=54950&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=54950&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=54950&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54950&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=54950&r=dst IIS Stability: http://bugs.php.net/fix.php?id=54950&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=54950&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=54950&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=54950&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=54950&r=mysqlcfg