PHP

PHP

Made by DeepSource

string casting in concatenation is redundant PHP-W1087

Anti-pattern
Major

When concatenating string with concatenation operator, implicitly casting a value to string type is not necessary. All types are by default casted to string.

Bad practice

class Greet
{
   public function getMessage(): string
   {
       // implicitly casting value to string is redundant here, it does it by default
       return 'Welcome ' . (string) $this->name;
   }
}

Recommended

class Greet
{
   public function getMessage(): string
   {
       return 'Welcome ' . $this->name;
   }
}

References