Hi,
I found a bug related to the Iterator
interface and its methods (next, current, ...)
<?php
namespace Devsense\Builtin;
class Test implements \Iterator
{
/**
* @var static[]
*/
public array $datas = [];
/**
* @var int
*/
protected int $_position = 0;
public function rewind(): ?static
{
$this->_position = 0;
return $this->current();
}
public function current(): ?static
{
return $this->datas[$this->_position] ?? null;
}
public function next(): ?static
{
$this->_position++;
return $this->current();
}
public function key(): mixed
{
return $this->_position;
}
public function valid(): bool
{
return array_key_exists($this->_position, $this->datas);
}
public function test(): bool
{
return true;
}
}
$test = new Test();
$current = $test->current();
$current->test();
$next = $test->next();
$next->test();
Got PHP0404
error on lines $current->test();
and $next->test();
FYI: https://www.php.net/manual/en/language.oop5.variance.php
Covariance allows a child's method to return a more specific type than the return type of its parent's method.
Thank you for the fix.