nikic / iter

Iteration primitives using generators
Other
1.12k stars 76 forks source link

PHP 8.1: fix deprecation notices #88

Closed jrfnl closed 3 years ago

jrfnl commented 3 years ago

A run on PHP 8.1 currently shows:

PHP Deprecated:  Return type of iter\rewindable\_RewindableGenerator::current() should either be compatible with Iterator::current(): mixed, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/runner/work/iter/iter/src/iter.rewindable.php on line 123
PHP Deprecated:  Return type of iter\rewindable\_RewindableGenerator::next() should either be compatible with Iterator::next(): void, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/runner/work/iter/iter/src/iter.rewindable.php on line 108
PHP Deprecated:  Return type of iter\rewindable\_RewindableGenerator::key() should either be compatible with Iterator::key(): mixed, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/runner/work/iter/iter/src/iter.rewindable.php on line 118
PHP Deprecated:  Return type of iter\rewindable\_RewindableGenerator::valid() should either be compatible with Iterator::valid(): bool, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/runner/work/iter/iter/src/iter.rewindable.php on line 113
PHP Deprecated:  Return type of iter\rewindable\_RewindableGenerator::rewind() should either be compatible with Iterator::rewind(): void, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/runner/work/iter/iter/src/iter.rewindable.php on line 103
PHP Deprecated:  Return type of iter\_CountableTestDummy::count() should either be compatible with Countable::count(): int, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/runner/work/iter/iter/test/iterTest.php on line 625

These deprecation notices relate to the Return types for internal methods RFC in PHP 8.1.

Using the attribute will silence the deprecation notices for now for those methods for which it cannot be added yet (PHP 8.0 mixed). For all other methods, the return type has now been added.

nikic commented 3 years ago

As the minimum version for the library is PHP 7.1, could you please add the return types instead?

jrfnl commented 3 years ago

@nikic No problem, what would you like me to use for the key() and current() methods though ? mixed is only available as of PHP 8.0.

nikic commented 3 years ago

@jrfnl Oh right, totally forgot about that. Let's keep the #[ReturnTypeWillChange] for those then and only add types to the other methods. There aren't any more specific types that could be used in this case.

jrfnl commented 3 years ago

@nikic Will do. It was the reason why I went with the attribute in the first place as it made the code consistent.

jrfnl commented 3 years ago

Rebased & updated. Should be good to go.