From 72515a4ed137071e441bb1aeda1940749e985844 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Wed, 22 Dec 2021 19:54:54 +0100 Subject: [PATCH 1/2] Fix warnings on PHP 8.1 With, PHP 8.1 lack of a return type hint for a method of a child class, whose parent has return type hint is considered mismatch. https://php.watch/versions/8.1/internal-method-return-types#no-return-type Since standard classes and interfaces started adding typehings, errors like the following are produced: PHP Deprecated: Return type of Violet\StreamingJsonEncoder\AbstractJsonEncoder::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice `void` type is only available since PHP 7.1 and `mixed` type requires PHP 8.0: https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.void https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.mixed To preserve compatibility with PHP < 8.0, we need to add the attribute. --- src/AbstractJsonEncoder.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/AbstractJsonEncoder.php b/src/AbstractJsonEncoder.php index 31adcc4..08964e0 100644 --- a/src/AbstractJsonEncoder.php +++ b/src/AbstractJsonEncoder.php @@ -123,6 +123,7 @@ private function initialize() * Returns the current number of step in the encoder. * @return int|null The current step number as integer or null if the current state is not valid */ + #[\ReturnTypeWillChange] public function key() { $this->initialize(); @@ -134,6 +135,7 @@ public function key() * Tells if the encoder has a valid current state. * @return bool True if the iterator has a valid state, false if not */ + #[\ReturnTypeWillChange] public function valid() { $this->initialize(); @@ -145,11 +147,13 @@ public function valid() * Returns the current value or state from the encoder. * @return mixed The current value or state from the encoder */ + #[\ReturnTypeWillChange] abstract public function current(); /** * Returns the JSON encoding to the beginning. */ + #[\ReturnTypeWillChange] public function rewind() { if ($this->step === 0) { @@ -172,6 +176,7 @@ public function rewind() /** * Iterates the next token or tokens to the output stream. */ + #[\ReturnTypeWillChange] public function next() { $this->initialize(); From 30c0570ae07a8bc461ec4ecff5b0886c8d3909b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riikka=20Kalliom=C3=A4ki?= Date: Mon, 27 Dec 2021 21:09:36 +0200 Subject: [PATCH 2/2] Add php 8.1 to test setup --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 50a8b28..f02c85e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] + php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] runs-on: ${{ matrix.operating-system }} steps: - name: Checkout