Type %s contains both iterable and array, which is redundant¶
Description¶
Since PHP 8.0 and the advent of union types, it is possible to write a type with duplicate type in it. This is obviously the case of the second function, in example.
It is less obvious to spot that array
and iterable
are redundant, yet, iterable
= array|Traversable
. So, iterable
is sufficient, to also cover array
.
This is a specific case of the general error that target any duplicate type in a definition.
Example¶
<?php
function foo() : array|iterable { }
function goo() : array|array { }
?>
Literal Examples¶
Type iterable|array contains both iterable and array, which is redundant
Solutions¶
Remove the
array
type, and only useiterable
for both.Remove the
iterable
type, and only usearray
for this type.
See Also¶
In more recent PHP versions, this error message is now Duplicate type %s is redundant.