From 527bdee2747dca166db9a51a952eba450bbd0d96 Mon Sep 17 00:00:00 2001 From: Mykola Silin Date: Mon, 15 Nov 2021 11:23:05 +0100 Subject: [PATCH] Fix compatibility of methods with native return type in PHP 8.1 (#1011) (cherry picked from commit 51ad17c3af192e34bc2e368a3c645a5a668f3e15) --- src/Error/Error.php | 2 ++ src/Language/SourceLocation.php | 2 ++ src/Type/Definition/Type.php | 5 ++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Error/Error.php b/src/Error/Error.php index e4ad9ac99..1e3ee0008 100644 --- a/src/Error/Error.php +++ b/src/Error/Error.php @@ -10,6 +10,7 @@ use GraphQL\Language\SourceLocation; use GraphQL\Utils\Utils; use JsonSerializable; +use ReturnTypeWillChange; use Throwable; use Traversable; use function array_filter; @@ -367,6 +368,7 @@ static function (SourceLocation $loc) : array { * @return mixed data which can be serialized by json_encode, * which is a value of any type other than a resource. */ + #[ReturnTypeWillChange] public function jsonSerialize() { return $this->toSerializableArray(); diff --git a/src/Language/SourceLocation.php b/src/Language/SourceLocation.php index 8877f8433..d0041831a 100644 --- a/src/Language/SourceLocation.php +++ b/src/Language/SourceLocation.php @@ -5,6 +5,7 @@ namespace GraphQL\Language; use JsonSerializable; +use ReturnTypeWillChange; class SourceLocation implements JsonSerializable { @@ -46,6 +47,7 @@ public function toSerializableArray() /** * @return int[] */ + #[ReturnTypeWillChange] public function jsonSerialize() { return $this->toSerializableArray(); diff --git a/src/Type/Definition/Type.php b/src/Type/Definition/Type.php index 864bcfed2..5dd67ceab 100644 --- a/src/Type/Definition/Type.php +++ b/src/Type/Definition/Type.php @@ -11,6 +11,8 @@ use GraphQL\Utils\Utils; use JsonSerializable; use ReflectionClass; +use ReturnTypeWillChange; + use function array_keys; use function array_merge; use function assert; @@ -308,7 +310,8 @@ public function assertValid() /** * @return string */ - public function jsonSerialize() + #[ReturnTypeWillChange] + public function jsonSerialize(): string { return $this->toString(); }