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.
class User
{
// invalid: Duplicate type `string` is redundant
public function getUser(): string|int|object|string
{
// method implementation here
}
}
class User
{
public function getUser(): string|int|object
{
// method implementation here
}
}