Skip to content

Commit 81b7229

Browse files
committed
Don't use instanceof_function directly
1 parent 7e40812 commit 81b7229

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Zend/zend_inheritance.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,15 @@ static zend_class_entry *lookup_class(const zend_function *fe, zend_string *name
216216
return NULL;
217217
}
218218

219+
/* Instanceof that's safe to use on unlinked classes. For the unlinked case, we only handle
220+
* class identity here. */
221+
static zend_bool unlinked_instanceof(zend_class_entry *ce1, zend_class_entry *ce2) {
222+
if ((ce1->ce_flags & ZEND_ACC_LINKED) && (ce2->ce_flags & ZEND_ACC_LINKED)) {
223+
return instanceof_function(ce1, ce2);
224+
}
225+
return ce1 == ce2;
226+
}
227+
219228
/* Unresolved means that class declarations that are currently not available are needed to
220229
* determine whether the inheritance is valid or not. At runtime UNRESOLVED should be treated
221230
* as an ERROR. */
@@ -254,15 +263,15 @@ static inheritance_status zend_perform_covariant_type_check(
254263
if (!fe_ce || !proto_ce) {
255264
return INHERITANCE_UNRESOLVED;
256265
}
257-
return instanceof_function(fe_ce, proto_ce) ? INHERITANCE_SUCCESS : INHERITANCE_ERROR;
266+
return unlinked_instanceof(fe_ce, proto_ce) ? INHERITANCE_SUCCESS : INHERITANCE_ERROR;
258267
} else if (ZEND_TYPE_CODE(proto_type) == IS_ITERABLE) {
259268
if (ZEND_TYPE_IS_CLASS(fe_type)) {
260269
zend_string *fe_class_name = resolve_class_name(fe, ZEND_TYPE_NAME(fe_type));
261270
zend_class_entry *fe_ce = lookup_class(fe, fe_class_name);
262271
if (!fe_ce) {
263272
return INHERITANCE_UNRESOLVED;
264273
}
265-
return instanceof_function(fe_ce, zend_ce_traversable)
274+
return unlinked_instanceof(fe_ce, zend_ce_traversable)
266275
? INHERITANCE_SUCCESS : INHERITANCE_ERROR;
267276
}
268277

0 commit comments

Comments
 (0)