Skip to content

Commit 0ad3f8d

Browse files
morrisonlevinikic
authored andcommitted
Extract _get_parent_class_name
This should probably be moved somewhere else and renamed.
1 parent 4866602 commit 0ad3f8d

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
@@ -184,29 +184,34 @@ 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 */
189+
static zend_string *_get_parent_class_name(zend_class_entry *ce)
190+
{ /* {{{ */
191+
zend_string *pname;
192+
193+
if (ce->ce_flags & ZEND_ACC_LINKED) {
194+
ZEND_ASSERT(ce->parent);
195+
pname = ce->parent->name;
196+
} else {
197+
pname = ce->parent_name;
198+
}
199+
200+
/* If there is a parent, it must have a name */
201+
ZEND_ASSERT(pname);
202+
return pname;
203+
}/* }}} */
204+
187205
static
188206
zend_string *_resolve_parent_and_self(const zend_function *fe, zend_string *name)
189-
{
207+
{ /* {{{ */
190208
zend_class_entry *ce = fe->common.scope;
191209
/* if there isn't a class then we shouldn't be resolving parent and self */
192210
ZEND_ASSERT(fe->common.scope);
193211

194212
switch (zend_get_class_fetch_type(name)) {
195213
case ZEND_FETCH_CLASS_PARENT:
196-
name = NULL;
197-
if (ce->ce_flags & ZEND_ACC_LINKED) {
198-
if (ce->parent && ce->parent->name) {
199-
name = ce->parent->name;
200-
}
201-
} else if (ce->parent_name) {
202-
name = ce->parent_name;
203-
}
204-
if (name == NULL) {
205-
zend_error_noreturn(E_COMPILE_ERROR,
206-
"Cannot use parent as type constraint in %s::%s() because %s does not have a parent type",
207-
ZEND_FN_SCOPE_NAME(fe), ZSTR_VAL(fe->common.function_name),
208-
ZEND_FN_SCOPE_NAME(fe));
209-
}
214+
name = _get_parent_class_name(ce);
210215
break;
211216

212217
case ZEND_FETCH_CLASS_SELF:
@@ -227,7 +232,7 @@ zend_string *_resolve_parent_and_self(const zend_function *fe, zend_string *name
227232
}
228233

229234
return zend_string_copy(name);
230-
}
235+
} /* }}} */
231236

232237
typedef enum {
233238
CONTRAVARIANT = -1,

0 commit comments

Comments
 (0)