-
-
Notifications
You must be signed in to change notification settings - Fork 938
Closed
phpstan/phpstan-src
#1860Labels
Description
Bug report
Given a property with native type iterable and PHPDoc type that allows array access, e.g. array, reading or writing to this property using array access is reported as an error.
Code snippet that reproduces the problem
<?php
class Foo
{
/** @var list<string>|(\ArrayAccess<int, string>&iterable<int, string>) */
private iterable $values;
/**
* @param list<string> $values
*/
public function update(array $values): void {
foreach ($this->values as $key => $_) {
unset($this->values[$key]);
}
foreach ($values as $value) {
$this->values[] = $value;
}
}
}PHPStan reports the following errors:
13 | Cannot access offset int on (ArrayAccess<int, string>&iterable<int, string>)\|iterable<int, string>.
-- | --
17 | Cannot access an offset on iterable<int, string>.
https://phpstan.org/r/42af72fd-760d-4132-8e1b-14449f2efe59
Expected output
No errors
Reactions are currently unavailable