Skip to content

Commit b1cebf3

Browse files
committed
- MFH Fix issues with static method invocation
1 parent cb27823 commit b1cebf3

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

Zend/zend_execute_API.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
582582
zend_op **original_opline_ptr;
583583
zend_class_entry *current_scope;
584584
zend_class_entry *calling_scope = NULL;
585+
zend_class_entry *check_scope_or_static = NULL;
585586
zval *current_this;
586587
zend_execute_data execute_data;
587588
zval *method_name;
@@ -719,21 +720,20 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
719720
} else {
720721
char *lcname = zend_str_tolower_dup(fname, clen);
721722
/* caution: lcname is not '\0' terminated */
722-
if (clen == sizeof("self") - 1 && memcmp(lcname, "self", sizeof("self") - 1) == 0) {
723-
ce_child = EG(active_op_array) ? EG(active_op_array)->scope : NULL;
724-
} else if (clen == sizeof("parent") - 1 && memcmp(lcname, "parent", sizeof("parent") - 1) == 0 && EG(active_op_array)->scope) {
725-
ce_child = EG(active_op_array) && EG(active_op_array)->scope ? EG(scope)->parent : NULL;
723+
if (calling_scope) {
724+
if (clen == sizeof("self") - 1 && memcmp(lcname, "self", sizeof("self") - 1) == 0) {
725+
ce_child = EG(active_op_array) ? EG(active_op_array)->scope : NULL;
726+
} else if (clen == sizeof("parent") - 1 && memcmp(lcname, "parent", sizeof("parent") - 1) == 0 && EG(active_op_array)->scope) {
727+
ce_child = EG(active_op_array) && EG(active_op_array)->scope ? EG(scope)->parent : NULL;
728+
}
726729
}
727730
efree(lcname);
728731
}
729732
if (!ce_child) {
730733
zend_error(E_ERROR, "Cannot call method %s() or method does not exist", fname);
731734
return FAILURE;
732735
}
733-
if (!instanceof_function(calling_scope, ce_child TSRMLS_CC)) {
734-
zend_error(E_ERROR, "Cannot call method %s() of class %s which is not a derived from %s", fname, ce_child->name, calling_scope->name);
735-
return 0;
736-
}
736+
check_scope_or_static = calling_scope;
737737
fci->function_table = &ce_child->function_table;
738738
calling_scope = ce_child;
739739
fname = fname + clen + 2;
@@ -760,6 +760,12 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
760760
EX(function_state).function =
761761
zend_std_get_static_method(calling_scope, function_name_lc, fname_len TSRMLS_CC);
762762
efree(function_name_lc);
763+
if (check_scope_or_static && EX(function_state).function
764+
&& !(EX(function_state).function->common.fn_flags & ZEND_ACC_STATIC)
765+
&& !instanceof_function(check_scope_or_static, calling_scope TSRMLS_CC)) {
766+
zend_error(E_ERROR, "Cannot call method %s() of class %s which is not a derived from %s", fname, calling_scope->name, check_scope_or_static->name);
767+
return 0;
768+
}
763769
} else {
764770
char *function_name_lc = zend_str_tolower_dup(fname, fname_len);
765771

0 commit comments

Comments
 (0)