Skip to content

Commit d19b6aa

Browse files
committed
Fix resolution of "parent" during inheritance check
We can't assume that the method we're checking against is part of the parent class...
1 parent 9977de0 commit d19b6aa

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
The parent class is not necessarily the class of the prototype
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
function test(): B {}
8+
}
9+
class B extends A {}
10+
class C extends B {
11+
function test(): parent {}
12+
}
13+
14+
?>
15+
===DONE===
16+
--EXPECT--
17+
===DONE===

Zend/zend_inheritance.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ static int zend_do_perform_type_hint_check(const zend_function *fe, zend_arg_inf
193193
fe_class_name = ZEND_TYPE_NAME(fe_arg_info->type);
194194
class_name = ZSTR_VAL(fe_class_name);
195195
class_name_len = ZSTR_LEN(fe_class_name);
196-
if (class_name_len == sizeof("parent")-1 && !strcasecmp(class_name, "parent") && proto->common.scope) {
197-
fe_class_name = zend_string_copy(proto->common.scope->name);
196+
if (class_name_len == sizeof("parent")-1 && !strcasecmp(class_name, "parent") && fe->common.scope && fe->common.scope->parent) {
197+
fe_class_name = zend_string_copy(fe->common.scope->parent->name);
198198
} else if (class_name_len == sizeof("self")-1 && !strcasecmp(class_name, "self") && fe->common.scope) {
199199
fe_class_name = zend_string_copy(fe->common.scope->name);
200200
} else {

0 commit comments

Comments
 (0)