Skip to content

Commit 1c6bea2

Browse files
committed
Extract _get_parent_class_name
This should probably be moved somewhere else and renamed.
1 parent d4022ca commit 1c6bea2

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
@@ -174,29 +174,34 @@ static zend_always_inline zend_bool zend_iterable_compatibility_check(zend_arg_i
174174
}
175175
/* }}} */
176176

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

184202
switch (zend_get_class_fetch_type(name)) {
185203
case ZEND_FETCH_CLASS_PARENT:
186-
name = NULL;
187-
if (ce->ce_flags & ZEND_ACC_LINKED) {
188-
if (ce->parent && ce->parent->name) {
189-
name = ce->parent->name;
190-
}
191-
} else if (ce->parent_name) {
192-
name = ce->parent_name;
193-
}
194-
if (name == NULL) {
195-
zend_error_noreturn(E_COMPILE_ERROR,
196-
"Cannot use parent as type constraint in %s::%s() because %s does not have a parent type",
197-
ZEND_FN_SCOPE_NAME(fe), ZSTR_VAL(fe->common.function_name),
198-
ZEND_FN_SCOPE_NAME(fe));
199-
}
204+
name = _get_parent_class_name(ce);
200205
break;
201206

202207
case ZEND_FETCH_CLASS_SELF:
@@ -217,7 +222,7 @@ zend_string *_resolve_parent_and_self(const zend_function *fe, zend_string *name
217222
}
218223

219224
return zend_string_copy(name);
220-
}
225+
} /* }}} */
221226

222227
typedef enum {
223228
CONTRAVARIANT = -1,

0 commit comments

Comments
 (0)