Skip to content

Commit 72515a4

Browse files
jtojnarRiimu
authored andcommitted
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.
1 parent 89ed24c commit 72515a4

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/AbstractJsonEncoder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ private function initialize()
123123
* Returns the current number of step in the encoder.
124124
* @return int|null The current step number as integer or null if the current state is not valid
125125
*/
126+
#[\ReturnTypeWillChange]
126127
public function key()
127128
{
128129
$this->initialize();
@@ -134,6 +135,7 @@ public function key()
134135
* Tells if the encoder has a valid current state.
135136
* @return bool True if the iterator has a valid state, false if not
136137
*/
138+
#[\ReturnTypeWillChange]
137139
public function valid()
138140
{
139141
$this->initialize();
@@ -145,11 +147,13 @@ public function valid()
145147
* Returns the current value or state from the encoder.
146148
* @return mixed The current value or state from the encoder
147149
*/
150+
#[\ReturnTypeWillChange]
148151
abstract public function current();
149152

150153
/**
151154
* Returns the JSON encoding to the beginning.
152155
*/
156+
#[\ReturnTypeWillChange]
153157
public function rewind()
154158
{
155159
if ($this->step === 0) {
@@ -172,6 +176,7 @@ public function rewind()
172176
/**
173177
* Iterates the next token or tokens to the output stream.
174178
*/
179+
#[\ReturnTypeWillChange]
175180
public function next()
176181
{
177182
$this->initialize();

0 commit comments

Comments
 (0)