#39173 [Csd->Bgs]: Return of DOMDocument methods misbehave if an error handler is set

From: Date: Tue, 17 Oct 2006 08:17:17 +0000
Subject: #39173 [Csd->Bgs]: Return of DOMDocument methods misbehave if an error handler is set
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-103618@lists.php.net to get a copy of this message
ID: 39173 Updated by: tony2001@php.net Reported By: daniel dot gorski at develnet dot org -Status: Closed +Status: Bogus -Bug Type: Scripting Engine problem +Bug Type: DOM XML related Operating System: Linux PHP Version: 5.2.0RC5 Previous Comments: ------------------------------------------------------------------------ [2006-10-17 05:19:25] daniel dot gorski at develnet dot org Forget about this issue. I was wrong. Sorry. ------------------------------------------------------------------------ [2006-10-17 04:39:47] daniel dot gorski at develnet dot org To make it more clear: <http://www.php.net/manual/en/function.dom-domdocument-load.php> <http://www.php.net/manual/en/function.dom-domdocument-loadxml.php> claim that these methods: [...] "Returns TRUE on success or FALSE on failure." The behaviour is IMO different to invocations like @fopen, @feof etc. Let there be light. ------------------------------------------------------------------------ [2006-10-17 04:17:01] daniel dot gorski at develnet dot org Description: ------------ If the set_error_handler() is set, the DOM-methods do not care about '@' if they run into an error/warning. When one tries to load a broken XML document via the DOMDocument#load / DOMDocument#loadXML (maybe others?) the warning won't be supressed, by using '@' if the set_error_handler() has been set before. If no set_error_handler() has been set before, the DOM methods behave as expected in this very case. The problem here is, that if one wants to use his own error handler, the mentioned DOM functions will break the program flow, without any chance of recovery. From my POV, this is easy to fix, but important to have. Please take a look at it. Thank you. Reproduce code: --------------- <?php // Removing this function call will do. set_error_handler('myErrorHandler', E_ALL | E_STRICT | E_RECOVERABLE_ERROR); function myErrorHandler($severity, $msg) { die($msg); } // --- $dom = new DOMDocument(); $flag = @$dom->loadXML('<root><BROKEN-ELEMENT></root>'); // -----^ echo $flag ? 'Passed' : 'Failed'; ?> Expected result: ---------------- Output of 'Failed' string. Actual result: -------------- Error (Warning?): DOMDocument::loadXML() [function.DOMDocument-loadXML]: Opening and ending tag mismatch: BROKEN-ELEMENT line 1 and root in Entity, line: 1 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=39173&edit=1

« previous php.bugs (#103618) next »