PHP

PHP

By DeepSource

string casting in concatenation is redundant PHP-W1087

Anti-pattern

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

Examples

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