Merge branch 'PHP-8.0'

* PHP-8.0:
  Don't autoload classes during covariant type check against mixed
This commit is contained in:
Nikita Popov 2021-05-10 09:46:49 +02:00
commit f71bfe4544
2 changed files with 27 additions and 0 deletions

View file

@ -0,0 +1,20 @@
--TEST--
Everything is trivially a subtype of mixed
--FILE--
<?php
spl_autoload_register(function($class) {
echo "Loading $class\n";
});
class A {
public function test(): mixed {}
}
class B extends A {
public function test(): X {}
}
?>
===DONE===
--EXPECT--
===DONE===

View file

@ -436,6 +436,13 @@ static inheritance_status zend_perform_covariant_type_check(
{
ZEND_ASSERT(ZEND_TYPE_IS_SET(fe_type) && ZEND_TYPE_IS_SET(proto_type));
/* Apart from void, everything is trivially covariant to the mixed type.
* Handle this case separately to ensure it never requires class loading. */
if (ZEND_TYPE_PURE_MASK(proto_type) == MAY_BE_ANY &&
!ZEND_TYPE_CONTAINS_CODE(fe_type, IS_VOID)) {
return INHERITANCE_SUCCESS;
}
/* Builtin types may be removed, but not added */
uint32_t fe_type_mask = ZEND_TYPE_PURE_MASK(fe_type);
uint32_t proto_type_mask = ZEND_TYPE_PURE_MASK(proto_type);