Skip to content

Commit 87a5212

Browse files
committed
Fix behaviour that proper callables could change
1 parent d36682e commit 87a5212

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

ext/xml/tests/xml_set_object_multiple_times.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class A {
1515
xml_set_object($parser, $b);
1616
echo "A::start_element($name)\n";
1717
}
18+
public function PIHandler($parser, $target, $data) {
19+
echo "A::PIHandler($target)\n";
20+
}
1821
}
1922

2023
class B {
@@ -24,6 +27,9 @@ class B {
2427
public function end_element($parser, $name) {
2528
echo "B::end_element($name)\n";
2629
}
30+
public function PIHandler($parser, $target, $data) {
31+
echo "B::PIHandler($target)\n";
32+
}
2733
}
2834

2935
$a = new A;
@@ -32,11 +38,13 @@ $b = new B;
3238
$parser = xml_parser_create();
3339
xml_set_object($parser, $a);
3440
xml_set_element_handler($parser, "start_element", "end_handler");
41+
xml_set_processing_instruction_handler($parser, [$a, "PIHandler"]);
3542
xml_parse($parser, <<<XML
3643
<?xml version="1.0"?>
3744
<container>
3845
<child/>
3946
</container>
47+
<?pi-test data ?>
4048
XML);
4149

4250
?>
@@ -45,3 +53,4 @@ A::start_element(CONTAINER)
4553
B::start_element(CHILD)
4654
end_handler(CHILD)
4755
end_handler(CONTAINER)
56+
A::PIHandler(pi-test)

ext/xml/xml.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,15 +1078,20 @@ static bool php_xml_check_string_method_arg(
10781078
}
10791079

10801080
parser_handler_fcc->function_handler = method_ptr;
1081-
parser_handler_fcc->calling_scope = ce;
1081+
/* We set the calling scope to NULL to be able to differentiate a "method" set from a proper callable */
1082+
parser_handler_fcc->calling_scope = NULL;
10821083
parser_handler_fcc->called_scope = ce;
10831084
parser_handler_fcc->object = object;
10841085

10851086
return true;
10861087
}
10871088

10881089
#define PHP_XML_CHECK_NEW_THIS_METHODS(parser_to_check, new_this_obj, fcc_field) \
1089-
if (ZEND_FCC_INITIALIZED(parser_to_check->fcc_field) && parser_to_check->fcc_field.object == parser_to_check->object) { \
1090+
if ( \
1091+
ZEND_FCC_INITIALIZED(parser_to_check->fcc_field) \
1092+
&& parser_to_check->fcc_field.object == parser_to_check->object \
1093+
&& parser_to_check->fcc_field.calling_scope == NULL \
1094+
) { \
10901095
zend_string *method_name = zend_string_copy(parser_to_check->fcc_field.function_handler->common.function_name); \
10911096
zend_fcc_dtor(&parser_to_check->fcc_field); \
10921097
bool status = php_xml_check_string_method_arg(2, new_this_obj, method_name, &parser_to_check->fcc_field); \

0 commit comments

Comments
 (0)