|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-08-14 19:28 UTC] 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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 09:00:01 2025 UTC |
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... - DanSorry 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.