|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38454 warning upon disabling handler via xml_set_element_handler
Submitted: 2006-08-14 19:28 UTC Modified: 2006-08-15 22:49 UTC
From: dtorop933 at gmail dot com Assigned: rrichards
Status: Closed Package: XML related
PHP Version: 5.1.4 OS: Linux
Private report: No CVE-ID:
 [2006-08-14 19:28 UTC] dtorop933 at gmail dot com
The documentation for xml_set_element_handler says:

"If a handler function is set to an empty string, or FALSE, the handler in question is disabled."

Unfortunately, I get a PHP Warning if the handler is disabled (rather than, preferrably, silently skipping the handler).

I have tested this on 5.1.4 and 5.2.0RC2 from CVS.

This may be related to bug #2377?

Reproduce code:
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, '', '') or
  die("Could not set up element handlers\n");

xml_parse($xml_parser, '<test/>', TRUE) or
  die("Could not parse XML\n");

Expected result:

Actual result:
Warning: xml_parse(): Unable to call handler () in /tmp/handler_test.php on line 6

Warning: xml_parse(): Unable to call handler () in /tmp/handler_test.php on line 6


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-14 19:37 UTC] dtorop933 at gmail dot com
Note that though the reproduce code which I give is not that useful, it isn't uncommon that one would want a start handler but no end handler (if one only wanted to grab attributes from start tags, for example).  In that case, it is annoying to see a warning every time the parser hits a disabled end tag handler.
 [2006-08-14 19:41 UTC]
Please try using this CVS snapshot:
For Windows:

 [2006-08-14 21:44 UTC] dtorop933 at gmail dot com

I tried the latest CVS snapshot with the same result.  Note that you will only see this if you have error_reporting in php.ini set to include E_WARNING.

The following patch seems to fix the problem for me:

--- php5.2-200608141830/ext/xml/xml.c.orig      2006-08-14 16:55:14.000000000 -0400
+++ php5.2-200608141830/ext/xml/xml.c   2006-08-14 17:41:31.000000000 -0400
@@ -383,6 +383,13 @@

+        /* if is FALSE or an empty string, disable this handler */
+        if ((Z_TYPE_PP(data) == IS_BOOL && !Z_BVAL_PP(data)) ||
+            (Z_TYPE_PP(data) == IS_STRING && !Z_STRLEN_PP(data))) {
+                *handler = NULL;
+                return;
+        }

        *handler = *data;

I'm not a PHP internals expert, hence I don't know if there is a better way to check the handler for empty string or FALSE (or if this is supposed to happen implicitly).

Note that this problem should exist in all functions which call xml_set_handler(), that is:


Thanks very much for taking the time to look at this...

- Dan
 [2006-08-14 22:18 UTC] dtorop933 at gmail dot com
Sorry to keep updating...  But I realize the patch above is a bit off as it should check for FALSE/strlen(0) before the argument is converted to a string.  The following alternate patch just checks for strlen(0) after the string conversion (at the cost of an unecessary string conversion in some cases).

--- php5.2-200608141830/ext/xml/xml.c.orig      2006-08-14 18:14:43.000000000 -0400
+++ php5.2-200608141830/ext/xml/xml.c   2006-08-14 18:13:02.000000000 -0400
@@ -381,6 +381,11 @@
        /* IS_ARRAY might indicate that we're using array($obj, 'method') syntax */
        if (Z_TYPE_PP(data) != IS_ARRAY) {
+                /* if is FALSE or an empty string, disable this handler */
+                if (!Z_STRLEN_PP(data)) {
+                        *handler = NULL;
+                        return;
+                }


With either patch, NULL will also work to cancel the handler.
 [2006-08-15 22:49 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Thu Nov 26 21:01:33 2015 UTC