Skip to content

Commit 908f0d5

Browse files
committed
Fix assertion failure due to unresolved parent
1 parent 64e36da commit 908f0d5

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Trait using parent used inside class without parent
3+
--FILE--
4+
<?php
5+
6+
trait T {
7+
function foo(parent $x) {}
8+
}
9+
10+
class A {
11+
use T;
12+
}
13+
class B extends A {
14+
function foo(parent $x) {}
15+
}
16+
17+
?>
18+
--EXPECTF--
19+
Warning: Declaration of B::foo(A $x) should be compatible with A::foo(parent $x) in %s on line %d

Zend/zend_inheritance.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,34 +184,27 @@ static zend_always_inline zend_bool zend_iterable_compatibility_check(zend_arg_i
184184
}
185185
/* }}} */
186186

187-
/* todo: this is probably useful elsewhere too */
188-
/* caller is responsible for adding any necessary refcount */
189187
static zend_string *_get_parent_class_name(zend_class_entry *ce)
190-
{ /* {{{ */
191-
zend_string *pname;
192-
188+
{
193189
if (ce->ce_flags & ZEND_ACC_LINKED) {
194-
ZEND_ASSERT(ce->parent);
195-
pname = ce->parent->name;
190+
return ce->parent ? ce->parent->name : NULL;
196191
} else {
197-
pname = ce->parent_name;
192+
return ce->parent_name;
198193
}
194+
}
199195

200-
/* If there is a parent, it must have a name */
201-
ZEND_ASSERT(pname);
202-
return pname;
203-
}/* }}} */
204-
205-
static
206-
zend_string *_resolve_parent_and_self(const zend_function *fe, zend_string *name)
196+
static zend_string *_resolve_parent_and_self(const zend_function *fe, zend_string *name)
207197
{ /* {{{ */
208198
zend_class_entry *ce = fe->common.scope;
209199
/* if there isn't a class then we shouldn't be resolving parent and self */
210-
ZEND_ASSERT(fe->common.scope);
200+
ZEND_ASSERT(ce);
211201

212202
switch (zend_get_class_fetch_type(name)) {
213203
case ZEND_FETCH_CLASS_PARENT:
214204
name = _get_parent_class_name(ce);
205+
if (!name) {
206+
return NULL;
207+
}
215208
break;
216209

217210
case ZEND_FETCH_CLASS_SELF:
@@ -262,12 +255,19 @@ _inheritance_status _check_covariance(
262255
}
263256

264257
if (ZEND_TYPE_IS_CLASS(fe_type)) {
265-
zend_string *fe_class_name =
266-
_resolve_parent_and_self(fe, ZEND_TYPE_NAME(fe_type));
267258
_inheritance_status code;
259+
zend_string *fe_class_name = _resolve_parent_and_self(fe, ZEND_TYPE_NAME(fe_type));
260+
if (!fe_class_name) {
261+
return INHERITANCE_UNRESOLVED;
262+
}
263+
268264
if (ZEND_TYPE_IS_CLASS(proto_type)) {
269265
zend_string *proto_class_name =
270266
_resolve_parent_and_self(proto, ZEND_TYPE_NAME(proto_type));
267+
if (!proto_class_name) {
268+
zend_string_free(fe_class_name);
269+
return INHERITANCE_UNRESOLVED;
270+
}
271271

272272
if (zend_string_equals_ci(fe_class_name, proto_class_name)) {
273273
code = INHERITANCE_SUCCESS;

0 commit comments

Comments
 (0)