Skip to content

Use true return type for XML functions which always return true #9539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions ext/xml/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ PHP_FUNCTION(xml_set_object)
zval_ptr_dtor(&parser->object);
ZVAL_OBJ_COPY(&parser->object, Z_OBJ_P(mythis));

RETVAL_TRUE;
RETURN_TRUE;
}
/* }}} */

Expand All @@ -1070,7 +1070,8 @@ PHP_FUNCTION(xml_set_element_handler)
xml_set_handler(&parser->startElementHandler, shdl);
xml_set_handler(&parser->endElementHandler, ehdl);
XML_SetElementHandler(parser->parser, _xml_startElementHandler, _xml_endElementHandler);
RETVAL_TRUE;

RETURN_TRUE;
}
/* }}} */

Expand All @@ -1087,7 +1088,8 @@ PHP_FUNCTION(xml_set_character_data_handler)
parser = Z_XMLPARSER_P(pind);
xml_set_handler(&parser->characterDataHandler, hdl);
XML_SetCharacterDataHandler(parser->parser, _xml_characterDataHandler);
RETVAL_TRUE;

RETURN_TRUE;
}
/* }}} */

Expand All @@ -1104,7 +1106,8 @@ PHP_FUNCTION(xml_set_processing_instruction_handler)
parser = Z_XMLPARSER_P(pind);
xml_set_handler(&parser->processingInstructionHandler, hdl);
XML_SetProcessingInstructionHandler(parser->parser, _xml_processingInstructionHandler);
RETVAL_TRUE;

RETURN_TRUE;
}
/* }}} */

Expand All @@ -1121,7 +1124,8 @@ PHP_FUNCTION(xml_set_default_handler)
parser = Z_XMLPARSER_P(pind);
xml_set_handler(&parser->defaultHandler, hdl);
XML_SetDefaultHandler(parser->parser, _xml_defaultHandler);
RETVAL_TRUE;

RETURN_TRUE;
}
/* }}} */

Expand All @@ -1138,7 +1142,8 @@ PHP_FUNCTION(xml_set_unparsed_entity_decl_handler)
parser = Z_XMLPARSER_P(pind);
xml_set_handler(&parser->unparsedEntityDeclHandler, hdl);
XML_SetUnparsedEntityDeclHandler(parser->parser, _xml_unparsedEntityDeclHandler);
RETVAL_TRUE;

RETURN_TRUE;
}
/* }}} */

Expand All @@ -1155,7 +1160,8 @@ PHP_FUNCTION(xml_set_notation_decl_handler)
parser = Z_XMLPARSER_P(pind);
xml_set_handler(&parser->notationDeclHandler, hdl);
XML_SetNotationDeclHandler(parser->parser, _xml_notationDeclHandler);
RETVAL_TRUE;

RETURN_TRUE;
}
/* }}} */

Expand All @@ -1172,7 +1178,8 @@ PHP_FUNCTION(xml_set_external_entity_ref_handler)
parser = Z_XMLPARSER_P(pind);
xml_set_handler(&parser->externalEntityRefHandler, hdl);
XML_SetExternalEntityRefHandler(parser->parser, (void *) _xml_externalEntityRefHandler);
RETVAL_TRUE;

RETURN_TRUE;
}
/* }}} */

Expand All @@ -1189,7 +1196,8 @@ PHP_FUNCTION(xml_set_start_namespace_decl_handler)
parser = Z_XMLPARSER_P(pind);
xml_set_handler(&parser->startNamespaceDeclHandler, hdl);
XML_SetStartNamespaceDeclHandler(parser->parser, _xml_startNamespaceDeclHandler);
RETVAL_TRUE;

RETURN_TRUE;
}
/* }}} */

Expand All @@ -1206,7 +1214,8 @@ PHP_FUNCTION(xml_set_end_namespace_decl_handler)
parser = Z_XMLPARSER_P(pind);
xml_set_handler(&parser->endNamespaceDeclHandler, hdl);
XML_SetEndNamespaceDeclHandler(parser->parser, _xml_endNamespaceDeclHandler);
RETVAL_TRUE;

RETURN_TRUE;
}
/* }}} */

Expand Down Expand Up @@ -1406,6 +1415,7 @@ PHP_FUNCTION(xml_parser_set_option)
if (parser->toffset < 0) {
php_error_docref(NULL, E_WARNING, "tagstart ignored, because it is out of range");
parser->toffset = 0;
/* TODO Should this return false? */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should throw a ValueError, but it might not be the best idea to change that now for BC reasons.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably should in the long run, but currently it's an error condition which returns true which is somewhat awkward.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! Given that we currently type as bool, returning false in this case appears to be the best solution for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'd probably stay with true + add this to the PHP 9.0 warning promotion RFC when the time comes, but I don't mind returning false.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's also fair, as it has been this behaviour for a while... PHP does have some oddities.

}
break;
case PHP_XML_OPTION_SKIP_WHITE:
Expand All @@ -1431,7 +1441,8 @@ PHP_FUNCTION(xml_parser_set_option)
RETURN_THROWS();
break;
}
RETVAL_TRUE;

RETURN_TRUE;
}
/* }}} */

Expand Down
22 changes: 11 additions & 11 deletions ext/xml/xml.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,37 +138,37 @@ function xml_parser_create(?string $encoding = null): XMLParser {}

function xml_parser_create_ns(?string $encoding = null, string $separator = ":"): XMLParser {}

function xml_set_object(XMLParser $parser, object $object): bool {}
function xml_set_object(XMLParser $parser, object $object): true {}

/**
* @param callable $start_handler
* @param callable $end_handler
*/
function xml_set_element_handler(XMLParser $parser, $start_handler, $end_handler): bool {}
function xml_set_element_handler(XMLParser $parser, $start_handler, $end_handler): true {}

/** @param callable $handler */
function xml_set_character_data_handler(XMLParser $parser, $handler): bool {}
function xml_set_character_data_handler(XMLParser $parser, $handler): true {}

/** @param callable $handler */
function xml_set_processing_instruction_handler(XMLParser $parser, $handler): bool {}
function xml_set_processing_instruction_handler(XMLParser $parser, $handler): true {}

/** @param callable $handler */
function xml_set_default_handler(XMLParser $parser, $handler): bool {}
function xml_set_default_handler(XMLParser $parser, $handler): true {}

/** @param callable $handler */
function xml_set_unparsed_entity_decl_handler(XMLParser $parser, $handler): bool {}
function xml_set_unparsed_entity_decl_handler(XMLParser $parser, $handler): true {}

/** @param callable $handler */
function xml_set_notation_decl_handler(XMLParser $parser, $handler): bool {}
function xml_set_notation_decl_handler(XMLParser $parser, $handler): true {}

/** @param callable $handler */
function xml_set_external_entity_ref_handler(XMLParser $parser, $handler): bool {}
function xml_set_external_entity_ref_handler(XMLParser $parser, $handler): true {}

/** @param callable $handler */
function xml_set_start_namespace_decl_handler(XMLParser $parser, $handler): bool {}
function xml_set_start_namespace_decl_handler(XMLParser $parser, $handler): true {}

/** @param callable $handler */
function xml_set_end_namespace_decl_handler(XMLParser $parser, $handler): bool {}
function xml_set_end_namespace_decl_handler(XMLParser $parser, $handler): true {}

function xml_parse(XMLParser $parser, string $data, bool $is_final = false): int {}

Expand All @@ -192,7 +192,7 @@ function xml_get_current_byte_index(XMLParser $parser): int {}
function xml_parser_free(XMLParser $parser): bool {}

/** @param string|int $value */
function xml_parser_set_option(XMLParser $parser, int $option, $value): bool {}
function xml_parser_set_option(XMLParser $parser, int $option, $value): true {}

/** @refcount 1 */
function xml_parser_get_option(XMLParser $parser, int $option): string|int {}
Expand Down
10 changes: 5 additions & 5 deletions ext/xml/xml_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.