Skip to content

Commit f71bfe4

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Don't autoload classes during covariant type check against mixed
2 parents e0b947a + 7fbfcfa commit f71bfe4

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
@@ -436,6 +436,13 @@ static inheritance_status zend_perform_covariant_type_check(
436436
{
437437
ZEND_ASSERT(ZEND_TYPE_IS_SET(fe_type) && ZEND_TYPE_IS_SET(proto_type));
438438

439+
/* Apart from void, everything is trivially covariant to the mixed type.
440+
* Handle this case separately to ensure it never requires class loading. */
441+
if (ZEND_TYPE_PURE_MASK(proto_type) == MAY_BE_ANY &&
442+
!ZEND_TYPE_CONTAINS_CODE(fe_type, IS_VOID)) {
443+
return INHERITANCE_SUCCESS;
444+
}
445+
439446
/* Builtin types may be removed, but not added */
440447
uint32_t fe_type_mask = ZEND_TYPE_PURE_MASK(fe_type);
441448
uint32_t proto_type_mask = ZEND_TYPE_PURE_MASK(proto_type);

0 commit comments

Comments
 (0)