MIR1501
ImplicitToStringCast
An object that does not implement __toString() or Stringable is implicitly coerced to a string (e.g. in string concatenation or an interpolated string).
Example
Section titled “Example”<?phpclass Point { public function __construct(public int $x, public int $y) {}}
$p = new Point(1, 2);echo "Position: " . $p; // Point has no __toStringHow to fix
Section titled “How to fix”Implement __toString() on the class, or cast explicitly with (string) only after implementing it.
<?phpclass Point { public function __construct(public int $x, public int $y) {}
public function __toString(): string { return "({$this->x}, {$this->y})"; }}