Duplicate Type

<?php

class_alias('a', 'c');
use A as B;

// duplicate hidden type
function foo(array | iterable $b) {}

// d8plicate type
function foo2(a | b $b) {}

// a and c are always considered distinct
function foo3(a | c $b) {}

// PHP is smarter than this poor usage of DNF
function foo4((a & b) | (b & a) $b) {}

?>

Union types check for duplicate types, so array|array is not possible, nor if a class is aliased with a use expression: on the other hand, it is valid with a class alias, created with class_alias().

The last case is the union type that actually hides the type: here, iterable includes array, so PHP complains about a duplicate, which is not visible at first sight.

Note that intersectional types also check for duplicate types.

See Also

PHP Error Messages

PHP Features

Last updated: 14 July 2026