Skip to content

Commit 25b4696

Browse files
authored
ext/xml: Deprecate xml_set_object() and passing non-callable strings as handlers (#15293)
1 parent 6eca783 commit 25b4696

16 files changed

+102
-69
lines changed

NEWS

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

58+
- XML:
59+
. The xml_set_object() function has been deprecated. (Girgias)
60+
. Passing non-callable strings to the xml_set_*_handler() functions is now
61+
deprecated. (Girgias)
62+
5863
01 Aug 2024, PHP 8.4.0alpha4
5964

6065
- 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
@@ -478,6 +478,13 @@ PHP 8.4 UPGRADE NOTES
478478
. Unserializing strings using the uppercase 'S' tag is deprecated.
479479
RFC: https://wiki.php.net/rfc/deprecations_php_8_4
480480

481+
- XML:
482+
. The xml_set_object() function has been deprecated.
483+
RFC: https://wiki.php.net/rfc/deprecations_php_8_4#xml_set_object_and_xml_set_handler_with_string_method_names
484+
. Passing non-callable strings to the xml_set_*_handler() functions is now
485+
deprecated.
486+
RFC: https://wiki.php.net/rfc/deprecations_php_8_4#xml_set_object_and_xml_set_handler_with_string_method_names
487+
481488
========================================
482489
5. Changed Functions
483490
========================================

Zend/tests/bug34617.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ function boom()
1515
}
1616
boom();
1717
?>
18-
--EXPECT--
18+
--EXPECTF--
19+
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
1920
ok

ext/xml/tests/bug30266.phpt

Lines changed: 0 additions & 51 deletions
This file was deleted.

ext/xml/tests/bug32001.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ HERE;
100100

101101
$parser = xml_parser_create(NULL);
102102
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
103-
xml_set_object($parser, $this);
104-
xml_set_element_handler($parser, "start_element", "end_element");
103+
xml_set_element_handler($parser, $this->start_element(...), $this->end_element(...));
105104

106105
if ($this->chunk_size == 0) {
107106
$success = @xml_parse($parser, $data, true);

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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ class XML_Parser
2929
function parse($data)
3030
{
3131
$parser = xml_parser_create();
32-
xml_set_object($parser, $this);
33-
xml_set_notation_decl_handler($parser, "notation_decl_handler");
34-
xml_set_unparsed_entity_decl_handler($parser, "unparsed_entity_decl_handler");
32+
xml_set_notation_decl_handler($parser, $this->notation_decl_handler(...));
33+
xml_set_unparsed_entity_decl_handler($parser, $this->unparsed_entity_decl_handler(...));
3534
xml_parse($parser, $data, true);
3635
xml_parser_free($parser);
3736
}

0 commit comments

Comments
 (0)