[RFC] Adding a "Stringable" interface to PHP 8
| From: | Nicolas Grekas | Date: | Wed, 22 Jan 2020 15:46:42 +0000 |
| Subject: | [RFC] Adding a "Stringable" interface to PHP 8 | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-108214@lists.php.net to get a copy of this message | ||
Hello everyone,
as announced last week, I'm officially opening a discussion for adding a
"Stringable" interface to PHP 8.
The RFC and its rationale are presented here as required:
https://wiki.php.net/rfc/stringable
The patch is found on GitHub, where some discussions happened already, you
might be interested in having a look:
https://github.com/php/php-src/pull/5083
TL;DR, I think we need an interface to allow passing objects with a
__toString() method in a type-safe way, using the string|Stringable type.
Here is the stub of the proposal:
interface Stringable { public function __toString(): string; }
I invite everyone to review the RFC before commenting here as I tried to
sum up considerations that some already had before and that you might have
too.
Cheers,
Nicolas