ID: 38454 Updated by: [EMAIL PROTECTED] Reported By: dtorop933 at gmail dot com -Status: Assigned +Status: Closed Bug Type: XML related Operating System: Linux PHP Version: 5.1.4 Assigned To: rrichards New Comment:
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 http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2006-08-14 22:18:50] 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) { convert_to_string_ex(data); + /* if is FALSE or an empty string, disable this handler */ + if (!Z_STRLEN_PP(data)) { + *handler = NULL; + return; + } } zval_add_ref(data); With either patch, NULL will also work to cancel the handler. ------------------------------------------------------------------------ [2006-08-14 21:44:18] dtorop933 at gmail dot com Hi, 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 @@ convert_to_string_ex(data); } + /* 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; + } + zval_add_ref(data); *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: xml_set_element_handler xml_set_character_data_handler xml_set_processing_instruction_handler xml_set_default_handler xml_set_unparsed_entity_decl_handler xml_set_notation_decl_handler xml_set_external_entity_ref_handler xml_set_start_namespace_decl_handler xml_set_end_namespace_decl_handler Thanks very much for taking the time to look at this... - Dan ------------------------------------------------------------------------ [2006-08-14 19:41:04] [EMAIL PROTECTED] Please try using this CVS snapshot: http://snaps.php.net/php5.2-latest.tar.gz For Windows: http://snaps.php.net/win32/php5.2-win32-latest.zip ------------------------------------------------------------------------ [2006-08-14 19:37:55] 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:28:31] dtorop933 at gmail dot com Description: ------------ 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: --------------- <?php $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"); xml_parser_free($xml_parser); ?> Expected result: ---------------- [NO OUTPUT] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38454&edit=1
