Skip to content

Commit be540b3

Browse files
committed
Remove some special-casing in zend_call_method()
Don't treat the !fn_proxy && !obj_ce case differently. There doesn't seem to be any need for it, and it will result in subtly different behavior (e.g. it will accept "Foo::bar" syntax, but break as soon as you pass in an fn_proxy cache).
1 parent 5965610 commit be540b3

File tree

1 file changed

+36
-44
lines changed

1 file changed

+36
-44
lines changed

Zend/zend_interfaces.c

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ZEND_API zval* zend_call_method(zend_object *object, zend_class_entry *obj_ce, z
3636
{
3737
int result;
3838
zend_fcall_info fci;
39+
zend_fcall_info_cache fcic;
3940
zval retval;
4041
zval params[2];
4142

@@ -52,58 +53,49 @@ ZEND_API zval* zend_call_method(zend_object *object, zend_class_entry *obj_ce, z
5253
fci.param_count = param_count;
5354
fci.params = params;
5455
fci.no_separation = 1;
56+
ZVAL_UNDEF(&fci.function_name); /* Unused */
5557

56-
if (!fn_proxy && !obj_ce) {
57-
/* no interest in caching and no information already present that is
58-
* needed later inside zend_call_function. */
59-
ZVAL_STRINGL(&fci.function_name, function_name, function_name_len);
60-
result = zend_call_function(&fci, NULL);
61-
zval_ptr_dtor(&fci.function_name);
62-
} else {
63-
zend_fcall_info_cache fcic;
64-
ZVAL_UNDEF(&fci.function_name); /* Unused */
65-
66-
if (!obj_ce) {
67-
obj_ce = object ? object->ce : NULL;
68-
}
69-
if (!fn_proxy || !*fn_proxy) {
70-
if (EXPECTED(obj_ce)) {
71-
fcic.function_handler = zend_hash_str_find_ptr(
72-
&obj_ce->function_table, function_name, function_name_len);
73-
if (UNEXPECTED(fcic.function_handler == NULL)) {
74-
/* error at c-level */
75-
zend_error_noreturn(E_CORE_ERROR, "Couldn't find implementation for method %s::%s", ZSTR_VAL(obj_ce->name), function_name);
76-
}
77-
} else {
78-
fcic.function_handler = zend_fetch_function_str(function_name, function_name_len);
79-
if (UNEXPECTED(fcic.function_handler == NULL)) {
80-
/* error at c-level */
81-
zend_error_noreturn(E_CORE_ERROR, "Couldn't find implementation for function %s", function_name);
82-
}
83-
}
84-
if (fn_proxy) {
85-
*fn_proxy = fcic.function_handler;
58+
if (!obj_ce) {
59+
obj_ce = object ? object->ce : NULL;
60+
}
61+
if (!fn_proxy || !*fn_proxy) {
62+
if (EXPECTED(obj_ce)) {
63+
fcic.function_handler = zend_hash_str_find_ptr(
64+
&obj_ce->function_table, function_name, function_name_len);
65+
if (UNEXPECTED(fcic.function_handler == NULL)) {
66+
/* error at c-level */
67+
zend_error_noreturn(E_CORE_ERROR, "Couldn't find implementation for method %s::%s", ZSTR_VAL(obj_ce->name), function_name);
8668
}
8769
} else {
88-
fcic.function_handler = *fn_proxy;
70+
fcic.function_handler = zend_fetch_function_str(function_name, function_name_len);
71+
if (UNEXPECTED(fcic.function_handler == NULL)) {
72+
/* error at c-level */
73+
zend_error_noreturn(E_CORE_ERROR, "Couldn't find implementation for function %s", function_name);
74+
}
8975
}
76+
if (fn_proxy) {
77+
*fn_proxy = fcic.function_handler;
78+
}
79+
} else {
80+
fcic.function_handler = *fn_proxy;
81+
}
9082

91-
if (object) {
92-
fcic.called_scope = object->ce;
83+
if (object) {
84+
fcic.called_scope = object->ce;
85+
} else {
86+
zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data));
87+
88+
if (obj_ce &&
89+
(!called_scope ||
90+
!instanceof_function(called_scope, obj_ce))) {
91+
fcic.called_scope = obj_ce;
9392
} else {
94-
zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data));
95-
96-
if (obj_ce &&
97-
(!called_scope ||
98-
!instanceof_function(called_scope, obj_ce))) {
99-
fcic.called_scope = obj_ce;
100-
} else {
101-
fcic.called_scope = called_scope;
102-
}
93+
fcic.called_scope = called_scope;
10394
}
104-
fcic.object = object;
105-
result = zend_call_function(&fci, &fcic);
10695
}
96+
fcic.object = object;
97+
result = zend_call_function(&fci, &fcic);
98+
10799
if (result == FAILURE) {
108100
/* error at c-level */
109101
if (!obj_ce) {

0 commit comments

Comments
 (0)