Skip to content

Commit 7fbfcfa

Browse files
committed
Don't autoload classes during covariant type check against mixed
mixed should be behaving the same way as no type here, and not require X to be autoloaded. Everything apart from "void" is trivially covariant to "mixed".
1 parent 0906270 commit 7fbfcfa

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Everything is trivially a subtype of mixed
3+
--FILE--
4+
<?php
5+
6+
spl_autoload_register(function($class) {
7+
echo "Loading $class\n";
8+
});
9+
10+
class A {
11+
public function test(): mixed {}
12+
}
13+
class B extends A {
14+
public function test(): X {}
15+
}
16+
17+
?>
18+
===DONE===
19+
--EXPECT--
20+
===DONE===

Zend/zend_inheritance.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,13 @@ static inheritance_status zend_perform_covariant_type_check(
429429
{
430430
ZEND_ASSERT(ZEND_TYPE_IS_SET(fe_type) && ZEND_TYPE_IS_SET(proto_type));
431431

432+
/* Apart from void, everything is trivially covariant to the mixed type.
433+
* Handle this case separately to ensure it never requires class loading. */
434+
if (ZEND_TYPE_PURE_MASK(proto_type) == MAY_BE_ANY &&
435+
!ZEND_TYPE_CONTAINS_CODE(fe_type, IS_VOID)) {
436+
return INHERITANCE_SUCCESS;
437+
}
438+
432439
/* Builtin types may be removed, but not added */
433440
uint32_t fe_type_mask = ZEND_TYPE_PURE_MASK(fe_type);
434441
uint32_t proto_type_mask = ZEND_TYPE_PURE_MASK(proto_type);

0 commit comments

Comments
 (0)