@@ -1059,11 +1059,13 @@ static bool php_xml_check_string_method_arg(
1059
1059
zend_fcall_info_cache * const parser_handler_fcc
1060
1060
) {
1061
1061
if (ZSTR_LEN (method_name ) == 0 ) {
1062
+ ZEND_ASSERT (arg_num != 0 );
1062
1063
/* Unset handler */
1063
1064
return true;
1064
1065
}
1065
1066
1066
1067
if (!object ) {
1068
+ ZEND_ASSERT (arg_num != 0 );
1067
1069
zend_argument_value_error (arg_num , "an object must be set via xml_set_object() to be able to lookup method" );
1068
1070
return false;
1069
1071
}
@@ -1073,7 +1075,9 @@ static bool php_xml_check_string_method_arg(
1073
1075
zend_function * method_ptr = zend_hash_find_ptr (& ce -> function_table , lc_name );
1074
1076
zend_string_release_ex (lc_name , 0 );
1075
1077
if (!method_ptr ) {
1076
- zend_argument_value_error (arg_num , "method %s::%s() does not exist" , ZSTR_VAL (ce -> name ), ZSTR_VAL (method_name ));
1078
+ if (arg_num ) {
1079
+ zend_argument_value_error (arg_num , "method %s::%s() does not exist" , ZSTR_VAL (ce -> name ), ZSTR_VAL (method_name ));
1080
+ }
1077
1081
return false;
1078
1082
}
1079
1083
@@ -1086,17 +1090,19 @@ static bool php_xml_check_string_method_arg(
1086
1090
return true;
1087
1091
}
1088
1092
1089
- #define PHP_XML_CHECK_NEW_THIS_METHODS (parser_to_check , new_this_obj , fcc_field ) \
1093
+ #define PHP_XML_CHECK_NEW_THIS_METHODS (parser_to_check , new_this_obj , fcc_field , handler_set_method ) \
1090
1094
if ( \
1091
1095
ZEND_FCC_INITIALIZED(parser_to_check->fcc_field) \
1092
1096
&& parser_to_check->fcc_field.object == parser_to_check->object \
1093
1097
&& parser_to_check->fcc_field.calling_scope == NULL \
1094
1098
) { \
1095
1099
zend_string *method_name = zend_string_copy(parser_to_check->fcc_field.function_handler->common.function_name); \
1096
1100
zend_fcc_dtor(&parser_to_check->fcc_field); \
1097
- bool status = php_xml_check_string_method_arg(2 , new_this_obj, method_name, &parser_to_check->fcc_field); \
1101
+ bool status = php_xml_check_string_method_arg(0 , new_this_obj, method_name, &parser_to_check->fcc_field); \
1098
1102
if (status == false) { \
1099
- /* TODO Better error message */ RETURN_THROWS (); \
1103
+ zend_argument_value_error(2, "cannot safely swap to object of class %s as method \"%s\" does not exist which was set via " handler_set_method, \
1104
+ ZSTR_VAL(new_this_obj->ce->name), ZSTR_VAL(method_name)); \
1105
+ RETURN_THROWS(); \
1100
1106
} \
1101
1107
zend_fcc_addref(&parser_to_check->fcc_field); \
1102
1108
}
@@ -1117,17 +1123,17 @@ PHP_FUNCTION(xml_set_object)
1117
1123
new_this = Z_OBJ_P (mythis );
1118
1124
1119
1125
if (parser -> object ) {
1120
- PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , startElementHandler );
1121
- PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , endElementHandler );
1122
- PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , characterDataHandler );
1123
- PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , processingInstructionHandler );
1124
- PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , defaultHandler );
1125
- PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , unparsedEntityDeclHandler );
1126
- PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , notationDeclHandler );
1127
- PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , externalEntityRefHandler );
1128
- PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , unknownEncodingHandler );
1129
- PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , startNamespaceDeclHandler );
1130
- PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , endNamespaceDeclHandler );
1126
+ PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , startElementHandler , "xml_set_element_handler()" );
1127
+ PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , endElementHandler , "xml_set_element_handler()" );
1128
+ PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , characterDataHandler , "xml_set_character_data_handler()" );
1129
+ PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , processingInstructionHandler , "xml_set_processing_instruction_handler()" );
1130
+ PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , defaultHandler , "xml_set_default_handler()" );
1131
+ PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , unparsedEntityDeclHandler , "xml_set_unparsed_entity_decl_handler()" );
1132
+ PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , notationDeclHandler , "xml_set_notation_decl_handler()" );
1133
+ PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , externalEntityRefHandler , "xml_set_external_entity_ref_handler()" );
1134
+ // PHP_XML_CHECK_NEW_THIS_METHODS(parser, new_this, unknownEncodingHandler, "we_dont_have_a_function_for_this_loool()" );
1135
+ PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , startNamespaceDeclHandler , "xml_set_start_namespace_decl_handler()" );
1136
+ PHP_XML_CHECK_NEW_THIS_METHODS (parser , new_this , endNamespaceDeclHandler , "xml_set_end_namespace_decl_handler()" );
1131
1137
1132
1138
OBJ_RELEASE (parser -> object );
1133
1139
}
0 commit comments