Skip to content

Commit 499c926

Browse files
committed
ext/xml: Deprecate xml_set_object() and passing non-callable strings to handlers
1 parent 80ae7f7 commit 499c926

14 files changed

+112
-13
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ PHP NEWS
4545
. Implemented GH-15155 (Stream context is lost when custom stream wrapper is
4646
being filtered). (Quentin Dreyer)
4747

48+
- XML:
49+
. The xml_set_object() has been deprecated. (Girgis)
50+
. Passing non-callable strings to the xml_set_*_handler() functions is now
51+
deprecated. (Girgias)
52+
4853
01 Aug 2024, PHP 8.4.0alpha4
4954

5055
- GMP:

UPGRADING

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ PHP 8.4 UPGRADE NOTES
189189
This means that xml_set_object() must now always be called prior to setting
190190
method names as callables.
191191
Passing an empty string to disable the handler is still allowed,
192-
but not recommended.
192+
but deprecated.
193193

194194
- XMLReader:
195195
. Passing an invalid character encoding to XMLReader::open() or
@@ -470,6 +470,13 @@ PHP 8.4 UPGRADE NOTES
470470
. Unserializing strings using the uppercase 'S' tag is deprecated.
471471
RFC: https://wiki.php.net/rfc/deprecations_php_8_4
472472

473+
- XML:
474+
. The xml_set_object() has been deprecated.
475+
RFC: https://wiki.php.net/rfc/deprecations_php_8_4#xml_set_object_and_xml_set_handler_with_string_method_names
476+
. Passing non-callable strings to the xml_set_*_handler() functions is now
477+
deprecated.
478+
RFC: https://wiki.php.net/rfc/deprecations_php_8_4#xml_set_object_and_xml_set_handler_with_string_method_names
479+
473480
========================================
474481
5. Changed Functions
475482
========================================

ext/xml/tests/bug30266.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,8 @@ try {
4747
echo "OK\n";
4848
}
4949
?>
50-
--EXPECT--
50+
--EXPECTF--
51+
Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d
52+
53+
Deprecated: xml_set_element_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
5154
OK

ext/xml/tests/bug72793.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ $xml_parser->free();
3131

3232
?>
3333
===DONE===
34-
--EXPECT--
34+
--EXPECTF--
35+
Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d
3536
===DONE===

ext/xml/tests/set_element_handler_trampoline.phpt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ xml_parse($parser, $xml, true);
5959
xml_parser_free($parser);
6060

6161
?>
62-
--EXPECT--
62+
--EXPECTF--
6363
Both handlers are trampolines:
6464
Trampoline for start_handler
6565
Tag: A
@@ -75,6 +75,10 @@ Trampoline for end_handler
7575
Tag: A
7676

7777
Start handler is trampoline, end handler method string:
78+
79+
Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d
80+
81+
Deprecated: xml_set_element_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
7882
Trampoline for start_handler
7983
Tag: A
8084
Trampoline for start_handler
@@ -86,6 +90,10 @@ Method end handler: C
8690
Method end handler: A
8791

8892
End handler is trampoline, start handler method string:
93+
94+
Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d
95+
96+
Deprecated: xml_set_element_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
8997
Method start handler: A
9098
Method start handler: B
9199
Trampoline for end_handler

ext/xml/tests/set_handler_errors.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,20 @@ try {
4848
}
4949

5050
?>
51-
--EXPECT--
51+
--EXPECTF--
5252
Invalid $parser:
5353
TypeError: xml_set_processing_instruction_handler(): Argument #1 ($parser) must be of type XMLParser, stdClass given
5454
Invalid callable type true:
5555
TypeError: xml_set_processing_instruction_handler(): Argument #2 ($handler) must be of type callable|string|null
5656
Invalid callable type int:
5757
TypeError: xml_set_processing_instruction_handler(): Argument #2 ($handler) must be of type callable|string|null
5858
String not callable and no object set:
59+
60+
Deprecated: xml_set_processing_instruction_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
5961
ValueError: xml_set_processing_instruction_handler(): Argument #2 ($handler) an object must be set via xml_set_object() to be able to lookup method
6062
String non existent method on set object:
63+
64+
Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d
65+
66+
Deprecated: xml_set_processing_instruction_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
6167
ValueError: xml_set_processing_instruction_handler(): Argument #2 ($handler) method stdClass::nonexistent_method() does not exist

ext/xml/tests/xml_set_element_handler_errors.phpt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ try {
7474
}
7575

7676
?>
77-
--EXPECT--
77+
--EXPECTF--
7878
Invalid $parser:
7979
TypeError: xml_set_element_handler(): Argument #1 ($parser) must be of type XMLParser, stdClass given
8080
Invalid start callable type true:
@@ -86,10 +86,22 @@ TypeError: xml_set_element_handler(): Argument #2 ($start_handler) must be of ty
8686
Invalid end callable type int:
8787
TypeError: xml_set_element_handler(): Argument #3 ($end_handler) must be of type callable|string|null
8888
Invalid start callable, no object set and string not callable:
89+
90+
Deprecated: xml_set_element_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
8991
ValueError: xml_set_element_handler(): Argument #2 ($start_handler) an object must be set via xml_set_object() to be able to lookup method
9092
Invalid end callable, no object set and string not callable:
93+
94+
Deprecated: xml_set_element_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
9195
ValueError: xml_set_element_handler(): Argument #3 ($end_handler) an object must be set via xml_set_object() to be able to lookup method
9296
Invalid start callable, string non existent method on set object:
97+
98+
Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d
99+
100+
Deprecated: xml_set_element_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
93101
ValueError: xml_set_element_handler(): Argument #2 ($start_handler) method stdClass::nonexistent_method() does not exist
94102
Invalid end callable, string non existent method on set object:
103+
104+
Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d
105+
106+
Deprecated: xml_set_element_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
95107
ValueError: xml_set_element_handler(): Argument #3 ($end_handler) method stdClass::nonexistent_method() does not exist

ext/xml/tests/xml_set_notation_decl_handler_basic.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,14 @@ $p1 = new Xml_Parser();
5454
$p1->parse($xml);
5555
echo "Done\n";
5656
?>
57-
--EXPECT--
57+
--EXPECTF--
5858
Simple test of xml_set_notation_decl_handler(() function
59+
60+
Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d
61+
62+
Deprecated: xml_set_notation_decl_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
63+
64+
Deprecated: xml_set_unparsed_entity_decl_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
5965
notation_decl_handler called
6066
...Name=USDATE
6167
...Base=

ext/xml/tests/xml_set_object_multiple_times.phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ xml_parse($parser, <<<XML
4848
XML);
4949

5050
?>
51-
--EXPECT--
51+
--EXPECTF--
52+
Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d
53+
54+
Deprecated: xml_set_element_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
55+
56+
Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d
5257
A::start_element(CONTAINER)
5358
B::start_element(CHILD)
5459
end_handler(CHILD)

ext/xml/tests/xml_set_object_multiple_times_errors.phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ xml_parse($parser, <<<XML
4141
XML);
4242

4343
?>
44-
--EXPECT--
44+
--EXPECTF--
45+
Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d
46+
47+
Deprecated: xml_set_element_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
4548
A::start_element(CONTAINER)
49+
50+
Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d
4651
ValueError: xml_set_object(): Argument #2 ($object) cannot safely swap to object of class B as method "end_element" does not exist, which was set via xml_set_element_handler()

ext/xml/tests/xml_set_processing_instruction_handler_basic.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ $p1 = new Xml_Parser();
3535
$p1->parse($xml);
3636
echo "Done\n";
3737
?>
38-
--EXPECT--
38+
--EXPECTF--
3939
Simple test of xml_set_processing_instruction_handler() function
40+
41+
Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d
42+
43+
Deprecated: xml_set_processing_instruction_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
4044
Target: xml-stylesheet
4145
Data: href="default.xsl" type="text/xml"
4246
Done

ext/xml/xml.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "php.h"
2424

2525
#include "zend_variables.h"
26+
#include "zend_attributes.h"
2627
#include "ext/standard/info.h"
2728
#include "ext/standard/html.h" /* For php_next_utf8_char() */
2829

@@ -1184,6 +1185,13 @@ PHP_FUNCTION(xml_set_element_handler)
11841185
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "OF!S", &pind, xml_parser_ce, &start_fci, &start_fcc, &end_method_name) == SUCCESS) {
11851186
parser = Z_XMLPARSER_P(pind);
11861187

1188+
php_error_docref(NULL, E_DEPRECATED, "Passing non-callable strings is deprecated since 8.4");
1189+
if (UNEXPECTED(EG(exception))) {
1190+
zend_release_fcall_info_cache(&start_fcc);
1191+
zend_release_fcall_info_cache(&end_fcc);
1192+
RETURN_THROWS();
1193+
}
1194+
11871195
bool status = php_xml_check_string_method_arg(3, parser->object, end_method_name, &end_fcc);
11881196
if (status == false) {
11891197
zend_release_fcall_info_cache(&start_fcc);
@@ -1193,6 +1201,13 @@ PHP_FUNCTION(xml_set_element_handler)
11931201
} else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "OSF!", &pind, xml_parser_ce, &start_method_name, &end_fci, &end_fcc) == SUCCESS) {
11941202
parser = Z_XMLPARSER_P(pind);
11951203

1204+
php_error_docref(NULL, E_DEPRECATED, "Passing non-callable strings is deprecated since 8.4");
1205+
if (UNEXPECTED(EG(exception))) {
1206+
zend_release_fcall_info_cache(&start_fcc);
1207+
zend_release_fcall_info_cache(&end_fcc);
1208+
RETURN_THROWS();
1209+
}
1210+
11961211
bool status = php_xml_check_string_method_arg(2, parser->object, start_method_name, &start_fcc);
11971212
if (status == false) {
11981213
zend_release_fcall_info_cache(&start_fcc);
@@ -1203,6 +1218,11 @@ PHP_FUNCTION(xml_set_element_handler)
12031218
zend_release_fcall_info_cache(&start_fcc);
12041219
zend_release_fcall_info_cache(&end_fcc);
12051220

1221+
php_error_docref(NULL, E_DEPRECATED, "Passing non-callable strings is deprecated since 8.4");
1222+
if (UNEXPECTED(EG(exception))) {
1223+
RETURN_THROWS();
1224+
}
1225+
12061226
parser = Z_XMLPARSER_P(pind);
12071227

12081228
bool status = php_xml_check_string_method_arg(2, parser->object, start_method_name, &start_fcc);
@@ -1263,7 +1283,10 @@ static void php_xml_set_handler_parse_callable(
12631283
memcpy(parser_handler_fcc, &handler_fcc, sizeof(zend_fcall_info_cache));
12641284
} else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "OS", &pind, xml_parser_ce, &method_name) == SUCCESS) {
12651285
*parser = Z_XMLPARSER_P(pind);
1266-
1286+
php_error_docref(NULL, E_DEPRECATED, "Passing non-callable strings is deprecated since 8.4");
1287+
if (UNEXPECTED(EG(exception))) {
1288+
RETURN_THROWS();
1289+
}
12671290
bool status = php_xml_check_string_method_arg(2, (*parser)->object, method_name, parser_handler_fcc);
12681291
if (status == false) {
12691292
RETURN_THROWS();

ext/xml/xml.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ function xml_parser_create(?string $encoding = null): XMLParser {}
149149

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

152+
#[\Deprecated(since: '8.4', message: 'provide a proper method callable to xml_set_*_handler() functions')]
152153
function xml_set_object(XMLParser $parser, object $object): true {}
153154

154155
function xml_set_element_handler(XMLParser $parser, callable|string|null $start_handler, callable|string|null $end_handler): true {}

ext/xml/xml_arginfo.h

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)