diff --git a/src/Symfony/Component/ErrorHandler/DebugClassLoader.php b/src/Symfony/Component/ErrorHandler/DebugClassLoader.php index fe6227e814..04836ef31b 100644 --- a/src/Symfony/Component/ErrorHandler/DebugClassLoader.php +++ b/src/Symfony/Component/ErrorHandler/DebugClassLoader.php @@ -49,12 +49,9 @@ use ProxyManager\Proxy\ProxyInterface; class DebugClassLoader { private const SPECIAL_RETURN_TYPES = [ - 'mixed' => 'mixed', 'void' => 'void', 'null' => 'null', 'resource' => 'resource', - 'static' => 'object', - '$this' => 'object', 'boolean' => 'bool', 'true' => 'bool', 'false' => 'bool', @@ -69,7 +66,13 @@ class DebugClassLoader 'string' => 'string', 'self' => 'self', 'parent' => 'parent', - ]; + ] + (\PHP_VERSION_ID >= 80000 ? [ + '$this' => 'static', + ] : [ + 'mixed' => 'mixed', + 'static' => 'object', + '$this' => 'object', + ]); private const BUILTIN_RETURN_TYPES = [ 'void' => true, @@ -83,7 +86,10 @@ class DebugClassLoader 'string' => true, 'self' => true, 'parent' => true, - ]; + ] + (\PHP_VERSION_ID >= 80000 ? [ + 'mixed' => true, + 'static' => true, + ] : []); private const MAGIC_METHODS = [ '__set' => 'void', @@ -856,7 +862,7 @@ class DebugClassLoader } } - if ('void' === $normalizedType) { + if ('void' === $normalizedType || (\PHP_VERSION_ID >= 80000 && 'mixed' === $normalizedType)) { $nullable = false; } elseif (!isset(self::BUILTIN_RETURN_TYPES[$normalizedType]) && isset(self::SPECIAL_RETURN_TYPES[$normalizedType])) { // ignore other special return types diff --git a/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php b/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php index d0ff0afba8..c77d3711fc 100644 --- a/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php +++ b/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php @@ -370,7 +370,7 @@ class DebugClassLoaderTest extends TestCase error_reporting($e); restore_error_handler(); - $this->assertSame([ + $this->assertSame(array_merge([ 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeGrandParent::returnTypeGrandParent()" will return "string" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParentInterface::returnTypeParentInterface()" will return "string" as of its next major version. Doing the same in implementation "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeInterface::returnTypeInterface()" will return "string" as of its next major version. Doing the same in implementation "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', @@ -383,14 +383,21 @@ class DebugClassLoaderTest extends TestCase 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::manyIterables()" will return "array" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::nullableReturnableTypeNormalization()" will return "object" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::nonNullableReturnableTypeNormalization()" will return "void" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', - 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::commonNonObjectReturnedTypeNormalization()" will return "object" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::bracketsNormalization()" will return "array" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::booleanNormalization()" will return "bool" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::callableNormalization1()" will return "callable" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::callableNormalization2()" will return "callable" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::otherTypeNormalization()" will return "\ArrayIterator" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::arrayWithLessThanSignNormalization()" will return "array" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', - ], $deprecations); + ], \PHP_VERSION_ID >= 80000 ? [ + 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::this()" will return "static" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', + 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::mixed()" will return "mixed" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', + 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::nullableMixed()" will return "mixed" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', + 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::static()" will return "static" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', + ] : [ + 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::this()" will return "object" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', + 'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::static()" will return "object" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.', + ]), $deprecations); } } diff --git a/src/Symfony/Component/ErrorHandler/Tests/Fixtures/ReturnType.php b/src/Symfony/Component/ErrorHandler/Tests/Fixtures/ReturnType.php index 28682763b7..228bf7f4c6 100644 --- a/src/Symfony/Component/ErrorHandler/Tests/Fixtures/ReturnType.php +++ b/src/Symfony/Component/ErrorHandler/Tests/Fixtures/ReturnType.php @@ -35,12 +35,15 @@ class ReturnType extends ReturnTypeParent implements ReturnTypeInterface, Fixtur public function manyIterables() { } public function nullableReturnableTypeNormalization() { } public function nonNullableReturnableTypeNormalization() { } - public function commonNonObjectReturnedTypeNormalization() { } public function bracketsNormalization() { } public function booleanNormalization() { } public function callableNormalization1() { } public function callableNormalization2() { } public function otherTypeNormalization() { } public function arrayWithLessThanSignNormalization() { } + public function this() { } + public function mixed() { } + public function nullableMixed() { } + public function static() { } public function outsideMethod() { } } diff --git a/src/Symfony/Component/ErrorHandler/Tests/Fixtures/ReturnTypeParent.php b/src/Symfony/Component/ErrorHandler/Tests/Fixtures/ReturnTypeParent.php index 45f8abad74..145686c8dc 100644 --- a/src/Symfony/Component/ErrorHandler/Tests/Fixtures/ReturnTypeParent.php +++ b/src/Symfony/Component/ErrorHandler/Tests/Fixtures/ReturnTypeParent.php @@ -29,7 +29,7 @@ abstract class ReturnTypeParent extends ReturnTypeGrandParent implements ReturnT abstract public function realReturnTypeIsAlreadyThereWithNull(); /** - * @return mixed + * @return resource */ public function oneCommonNonObjectReturnedType() { @@ -143,13 +143,6 @@ abstract class ReturnTypeParent extends ReturnTypeGrandParent implements ReturnT { } - /** - * @return $this - */ - public function commonNonObjectReturnedTypeNormalization() - { - } - /** * @return \ArrayIterator[] */ @@ -192,6 +185,34 @@ abstract class ReturnTypeParent extends ReturnTypeGrandParent implements ReturnT { } + /** + * @return $this + */ + public function this() + { + } + + /** + * @return mixed + */ + public function mixed() + { + } + + /** + * @return mixed|null + */ + public function nullableMixed() + { + } + + /** + * @return static + */ + public function static() + { + } + /** * @return int */