-
-
Notifications
You must be signed in to change notification settings - Fork 947
Missing return types on Iterator::key() and current() are not reported #7415
Copy link
Copy link
Closed
phpstan/phpstan-src
#1491Labels
Description
Bug report
When implementing PHP's Iterator without native return types, PHPStan complains about that. This is great because this way we can find code that otherwise would trigger a runtime deprecation on PHP 8.1.
However, it does so on next(), next() and rewind(), but not on current() and key().
Code snippet that reproduces the problem
/**
* @implements Iterator<int, mixed>
*/
class MyIterator implements Iterator
{
public function current()
{
return null;
}
public function next()
{
}
public function key()
{
return 0;
}
public function valid()
{
return false;
}
public function rewind()
{
}
}https://phpstan.org/r/a8b27f70-a29e-42a8-8252-19a854325434
Expected output
I would expect five errors here, but I only get three. The PHP runtime triggers five runtime deprecations for that piece of code.
Did PHPStan help you today? Did it make you happy in any way?
PHPStan did help us a lot when migrating a legacy codebase to PHP 8.1.
Reactions are currently unavailable