Skip to content

Commit b16f82a

Browse files
committed
Check class visibility wrt to opcache
1 parent cc42184 commit b16f82a

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

Zend/zend_inheritance.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,28 @@ static zend_string *_resolve_parent_and_self(const zend_function *fe, zend_strin
226226
return zend_string_copy(name);
227227
} /* }}} */
228228

229+
static zend_bool class_visible(zend_class_entry *ce) {
230+
if (CG(in_compilation)) {
231+
return 1;
232+
}
233+
if (ce->type == ZEND_INTERNAL_CLASS) {
234+
return !(CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_CLASSES);
235+
} else {
236+
ZEND_ASSERT(ce->type == ZEND_USER_CLASS);
237+
return !(CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES)
238+
|| ce->info.user.filename == CG(compiled_filename);
239+
}
240+
}
241+
242+
zend_class_entry *lookup_class(zend_string *name) {
243+
zend_class_entry *ce = zend_lookup_class(name);
244+
if (!ce) {
245+
return NULL;
246+
}
247+
248+
return class_visible(ce) ? ce : NULL;
249+
}
250+
229251
typedef enum {
230252
INHERITANCE_UNRESOLVED = -1,
231253
INHERITANCE_ERROR = 0,
@@ -272,8 +294,8 @@ _inheritance_status _check_covariance(
272294
code = INHERITANCE_SUCCESS;
273295
} else {
274296
if (fe->common.type == ZEND_USER_FUNCTION) {
275-
zend_class_entry *fe_ce = zend_lookup_class(fe_class_name);
276-
zend_class_entry *proto_ce = zend_lookup_class(proto_class_name);
297+
zend_class_entry *fe_ce = lookup_class(fe_class_name);
298+
zend_class_entry *proto_ce = lookup_class(proto_class_name);
277299

278300
if (fe_ce && proto_ce) {
279301
code = instanceof_function(fe_ce, proto_ce)
@@ -289,7 +311,7 @@ _inheritance_status _check_covariance(
289311
}
290312
zend_string_release(proto_class_name);
291313
} else if (proto_type_code == IS_ITERABLE) {
292-
zend_class_entry *fe_ce = zend_lookup_class(fe_class_name);
314+
zend_class_entry *fe_ce = lookup_class(fe_class_name);
293315
if (fe_ce) {
294316
code = instanceof_function(fe_ce, zend_ce_traversable)
295317
? INHERITANCE_SUCCESS

0 commit comments

Comments
 (0)