Doc #55184 [Com]: DOMDocument::load() throws an exception instead of returning false on error

From: Date: Thu, 18 Aug 2011 09:41:22 +0000
Subject: Doc #55184 [Com]: DOMDocument::load() throws an exception instead of returning false on error
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-7031@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55184&edit=1 ID: 55184 Comment by: stuart at horuskol dot net Reported by: stuart at horuskol dot net Summary: DOMDocument::load() throws an exception instead of returning false on error Status: Feedback Type: Documentation Problem Package: Documentation problem PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Hi, If you look at my code you can see that I am catching the exceptions thrown by the call to DOMDocument::load and outputting the message in the exception. It is definitely not returning false. Previous Comments: ------------------------------------------------------------------------ [2011-08-17 13:26:12] bjori@php.net Not enough information was provided for us to be able to handle this bug. Please re-read the instructions at http://bugs.php.net/how-to-report.php If you can provide more information, feel free to add it to this bug and change the status back to "Open". Thank you for your interest in PHP. I'm confused. You are saying it throws exceptions.. But your example clearly shows it doesn't throw exceptions, just prints warnings and returns false.. ------------------------------------------------------------------------ [2011-07-11 22:14:39] stuart at horuskol dot net Description: ------------ --- From manual page: http://www.php.net/domdocument.load%23Errors/Exceptions --- The manual page reports that this method returns false on failure - however, testing this function has resulted in exceptions being thrown instead. Can the manual be updated to reflect this? Test script: --------------- Example XML files: http://horuskol.net/media/php/map-not-xml.xml http://horuskol.net/media/php/map-malformed-xml.xml <?php $dom = new DOMDocument(); try { if (!$dom->load('not-a-file')) { throw new Exception('Error loading source file'); } } catch (Exception $e) { echo $e->getMessage(); } try { if (!$dom->load('map-not-xml.xml')) { throw new Exception('Error loading source file'); } } catch (Exception $e) { echo $e->getMessage(); } try { if (!$dom->load('map-malformed-xml.xml')) { throw new Exception('Error loading source file'); } } catch (Exception $e) { echo $e->getMessage(); } Expected result: ---------------- Error loading source file Error loading source file Error loading source file Actual result: -------------- DOMDocument::load(): I/O warning : failed to load external entity "not-a-file" DOMDocument::load(): Start tag expected, '<' not found in map-not-xml.xml, line: 1 DOMDocument::load(): Couldn't find end of Start Tag malformed line 2 in map-malformed-xml.xml, line: 2 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55184&edit=1

« previous php.doc.bugs (#7031) next »