PHP Stringable Interface
Description
Since [PHP 8.0](PHP 8.0), the stringable interface[fn:stringable] is automatically added to classes that implement the __toString() method
Syntax
class Foo
{
public function __toString(): string
{
return ‘foo’;
}
}
function bar(string|Stringable $stringable) { /* … */ }
bar(new Foo());
bar(‘abc’);
Footnotes
[fn:stringable]https://wiki.php.net/rfc/stringable