#39173 [Opn->Csd]: Return of DOMDocument methods misbehave if an error handler is set
ID: 39173
User updated by: daniel dot gorski at develnet dot org
Reported By: daniel dot gorski at develnet dot org
-Status: Open
+Status: Closed
Bug Type: Scripting Engine problem
Operating System: Linux
PHP Version: 5.2.0RC5
New Comment:
Forget about this issue. I was wrong. Sorry.
Previous Comments:
------------------------------------------------------------------------
[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
Thread (4 messages)