mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-21 19:16:23 +00:00
517 B
517 B
date | id | title |
---|---|---|
2020-11-10 | f97470da-6833-4ecf-81e2-40dd04f6c2a1 | PHP Stringable Interface |
Description
Since PHP 8.0, the stringable interface1 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');