@@ -178,29 +178,34 @@ static zend_always_inline zend_bool zend_iterable_compatibility_check(zend_arg_i
178
178
}
179
179
/* }}} */
180
180
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
+
181
199
static
182
200
zend_string * _resolve_parent_and_self (const zend_function * fe , zend_string * name )
183
- {
201
+ { /* {{{ */
184
202
zend_class_entry * ce = fe -> common .scope ;
185
203
/* if there isn't a class then we shouldn't be resolving parent and self */
186
204
ZEND_ASSERT (fe -> common .scope );
187
205
188
206
switch (zend_get_class_fetch_type (name )) {
189
207
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 );
204
209
break ;
205
210
206
211
case ZEND_FETCH_CLASS_SELF :
@@ -221,7 +226,7 @@ zend_string *_resolve_parent_and_self(const zend_function *fe, zend_string *name
221
226
}
222
227
223
228
return zend_string_copy (name );
224
- }
229
+ } /* }}} */
225
230
226
231
typedef enum {
227
232
CONTRAVARIANT = -1 ,
0 commit comments