Skip to content

Commit 7e55317

Browse files
committed
Allow unlinked classes when performing in_compilation variance check
As preloading runs in in_compilation mode, we also need to allow use of unlinked classes in lookup_class().
1 parent ee934f8 commit 7e55317

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Zend/zend_inheritance.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,9 @@ static zend_bool class_visible(zend_class_entry *ce) {
239239

240240
static zend_class_entry *lookup_class(
241241
zend_class_entry *scope, zend_string *name, zend_bool register_unresolved) {
242-
zend_class_entry *ce;
242+
uint32_t flags = ZEND_FETCH_CLASS_ALLOW_UNLINKED | ZEND_FETCH_CLASS_NO_AUTOLOAD;
243+
zend_class_entry *ce = zend_lookup_class_ex(name, NULL, flags);
243244
if (!CG(in_compilation)) {
244-
uint32_t flags = ZEND_FETCH_CLASS_ALLOW_UNLINKED | ZEND_FETCH_CLASS_NO_AUTOLOAD;
245-
ce = zend_lookup_class_ex(name, NULL, flags);
246245
if (ce) {
247246
return ce;
248247
}
@@ -256,7 +255,6 @@ static zend_class_entry *lookup_class(
256255
zend_hash_add_empty_element(CG(delayed_autoloads), name);
257256
}
258257
} else {
259-
ce = zend_lookup_class_ex(name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
260258
if (ce && class_visible(ce)) {
261259
return ce;
262260
}

ext/opcache/tests/preload_variance.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ class C extends Z {
1414
public function method($a): self {}
1515
public function method2($a): C {}
1616
public function method3($a): object {}
17+
public function method4(D $a) {}
1718
}
1819
class D extends C {
1920
public function method($a): self {}
2021
public function method2($a): D {}
2122
public function method3($a): stdClass {}
23+
public function method4(C $a) {}
2224
}
2325

2426
// Works.

0 commit comments

Comments
 (0)