Skip to content

Commit d132392

Browse files
jrfnlnikic
authored andcommitted
PHP 8.1: fix deprecation notices
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](https://wiki.php.net/rfc/internal_method_return_types) 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.
1 parent c042eeb commit d132392

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/iter.rewindable.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ function callRewindable(callable $function, ...$args) {
4848
}
4949

5050
namespace iter\rewindable {
51+
52+
use ReturnTypeWillChange;
53+
5154
/**
5255
* These functions are just rewindable wrappers around the normal
5356
* non-rewindable functions from the iter namespace
@@ -100,26 +103,28 @@ public function __construct(callable $function, array $args) {
100103
$this->generator = null;
101104
}
102105

103-
public function rewind() {
106+
public function rewind(): void {
104107
$function = $this->function;
105108
$this->generator = $function(...$this->args);
106109
}
107110

108-
public function next() {
111+
public function next(): void {
109112
if (!$this->generator) { $this->rewind(); }
110113
$this->generator->next();
111114
}
112115

113-
public function valid() {
116+
public function valid(): bool {
114117
if (!$this->generator) { $this->rewind(); }
115118
return $this->generator->valid();
116119
}
117120

121+
#[ReturnTypeWillChange]
118122
public function key() {
119123
if (!$this->generator) { $this->rewind(); }
120124
return $this->generator->key();
121125
}
122126

127+
#[ReturnTypeWillChange]
123128
public function current() {
124129
if (!$this->generator) { $this->rewind(); }
125130
return $this->generator->current();

test/iterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ function() {
622622
}
623623

624624
class _CountableTestDummy implements \Countable {
625-
public function count() {
625+
public function count(): int {
626626
return 42;
627627
}
628628
}

0 commit comments

Comments
 (0)