Type %s is redundant as it is more restrictive than type %s¶
Description¶
DNF (Disjunctive Normal Form) types, added in PHP 8.2, allow an intersection group to be combined inside a union, as in (A&B)|C. If one of the union’s plain members already appears on its own, here A, then any intersection group built from that same name, such as A&B, cannot accept any value beyond what A alone already accepts: satisfying A&B always implies satisfying A.
PHP detects this purely by comparing the type names in the declaration, without loading any class, and rejects the more restrictive branch as dead code.
Example¶
<?php
interface A {}
interface B {}
function test(): (A&B)|A {}
?>
Literal Examples¶
Type A&B is redundant as it is more restrictive than type A
Solutions¶
Remove the redundant intersection group, and keep only the broader standalone type.
If the intersection group was meant to be independent, use a type that is not already implied by one of the union’s other members.
Changed Behavior¶
This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.