Skip to content

Commit ad67313

Browse files
committed
Extract _get_parent_class_name
This should probably be moved somewhere else and renamed.
1 parent 0b31517 commit ad67313

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

Zend/zend_inheritance.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -178,29 +178,34 @@ static zend_always_inline zend_bool zend_iterable_compatibility_check(zend_arg_i
178178
}
179179
/* }}} */
180180

181+
/* todo: this is probably useful elsewhere too */
182+
/* caller is responsible for adding any necessary refcount */
183+
static zend_string *_get_parent_class_name(zend_class_entry *ce)
184+
{ /* {{{ */
185+
zend_string *pname;
186+
187+
if (ce->ce_flags & ZEND_ACC_LINKED) {
188+
ZEND_ASSERT(ce->parent);
189+
pname = ce->parent->name;
190+
} else {
191+
pname = ce->parent_name;
192+
}
193+
194+
/* If there is a parent, it must have a name */
195+
ZEND_ASSERT(pname);
196+
return pname;
197+
}/* }}} */
198+
181199
static
182200
zend_string *_resolve_parent_and_self(const zend_function *fe, zend_string *name)
183-
{
201+
{ /* {{{ */
184202
zend_class_entry *ce = fe->common.scope;
185203
/* if there isn't a class then we shouldn't be resolving parent and self */
186204
ZEND_ASSERT(fe->common.scope);
187205

188206
switch (zend_get_class_fetch_type(name)) {
189207
case ZEND_FETCH_CLASS_PARENT:
190-
name = NULL;
191-
if (ce->ce_flags & ZEND_ACC_LINKED) {
192-
if (ce->parent && ce->parent->name) {
193-
name = ce->parent->name;
194-
}
195-
} else if (ce->parent_name) {
196-
name = ce->parent_name;
197-
}
198-
if (name == NULL) {
199-
zend_error_noreturn(E_COMPILE_ERROR,
200-
"Cannot use parent as type constraint in %s::%s() because %s does not have a parent type",
201-
ZEND_FN_SCOPE_NAME(fe), ZSTR_VAL(fe->common.function_name),
202-
ZEND_FN_SCOPE_NAME(fe));
203-
}
208+
name = _get_parent_class_name(ce);
204209
break;
205210

206211
case ZEND_FETCH_CLASS_SELF:
@@ -221,7 +226,7 @@ zend_string *_resolve_parent_and_self(const zend_function *fe, zend_string *name
221226
}
222227

223228
return zend_string_copy(name);
224-
}
229+
} /* }}} */
225230

226231
typedef enum {
227232
CONTRAVARIANT = -1,

0 commit comments

Comments
 (0)