PHP

PHP

Made by DeepSource

Use of duplicate type in Union types detected PHP-T1005

Bug risk
Critical

PHP provides the ability to declare more than one type(also known as Union types) to arguments, return type, and class properties. Here, the same types are being declared using union more than once, which would lead to an error during the runtime.

It is recommended to drop duplicate type declarations.

Bad practice

class User
{
    // invalid: Duplicate type `string` is redundant
    public function getUser(): string|int|object|string
    {
        // method implementation here
    }
}

Recommended

class User
{
    public function getUser(): string|int|object
    {
        // method implementation here
    }
}

References