Re: [PHP-DEV] [RFC] Adding a "Stringable" interface to PHP 8

This is only part of a thread. view whole thread
  108215
January 22, 2020 17:14 kontakt@beberlei.de (Benjamin Eberlei)
On Wed, Jan 22, 2020 at 4:47 PM Nicolas Grekas grekas+php@gmail.com>
wrote:

> 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 like the fact that you automatically add the string return type to existing methods to avoid BC break problems. Given that the engine enforces this with special code right now, i believe its a nice improvement to happen automatically.
> 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 >