php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39173 Return of DOMDocument methods misbehave if an error handler is set
Submitted: 2006-10-17 04:17 UTC Modified: 2006-10-17 08:17 UTC
From: daniel dot gorski at develnet dot org Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.0RC5 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: daniel dot gorski at develnet dot org
New email:
PHP Version: OS:

 

 [2006-10-17 04:17 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-17 04:39 UTC] 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 05:19 UTC] daniel dot gorski at develnet dot org
Forget about this issue. I was wrong. Sorry.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Sep 28 23:01:27 2024 UTC