Fix Iterator example for PHP 8.1+

The newly introduced tentative return types require us to specify
return types for the method implementation.  Since `mixed` is only
available as of PHP 8.0.0, we use the `ReturnTypeWillChange` attribute
to suppress the deprecation for now.

This includes user note 127109 (well, at least the actionable part of
it).
This commit is contained in:
Christoph M. Becker 2022-05-17 13:57:38 +02:00
parent cfaa7659da
commit 214335df7e
No known key found for this signature in database
GPG key ID: D66C9593118BCCB6

View file

@ -77,27 +77,29 @@ class myIterator implements Iterator {
$this->position = 0;
}
public function rewind() {
public function rewind(): void {
var_dump(__METHOD__);
$this->position = 0;
}
#[\ReturnTypeWillChange]
public function current() {
var_dump(__METHOD__);
return $this->array[$this->position];
}
#[\ReturnTypeWillChange]
public function key() {
var_dump(__METHOD__);
return $this->position;
}
public function next() {
public function next(): void {
var_dump(__METHOD__);
++$this->position;
}
public function valid() {
public function valid(): bool {
var_dump(__METHOD__);
return isset($this->array[$this->position]);
}