PHP

PHP

By DeepSource

Use of duplicate type in Union types detectedPHP-T1005

Bug risk

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.

Examples

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