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

This is only part of a thread. view whole thread
  108227
January 24, 2020 15:16 nicolas.grekas+php@gmail.com (Nicolas Grekas)
Le mer. 22 janv. 2020 à 20:03, Rowan Tommins collins@gmail.com> a
écrit :

> On Wed, 22 Jan 2020 at 15:47, 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 > > > > > I'm still unconvinced on this one, but I was digging into some of the uses > you linked to, to understand why it might be used. > > The background to the Symfony Validator one makes for some interesting > reading: https://github.com/symfony/symfony/pull/31083 and > https://www.drupal.org/project/drupal/issues/3029540 > > It seems that Symfony always intended this particular parameter to be a > string, but couldn't enforce that until PHP 7; Drupal abused it by passing > in an object, which happens to be stringable but have special behaviour in > the templating layer, leading to a compatibility break between the two > projects. In a sense it's just luck that the object in question implements > __toString(), rather than being a completely unrelated object, since Drupal > relies on it being passed back out unmodified. > > Nonetheless, it's an interesting use case, and it's interesting to > speculate whether it might have been designed how it is anyway without that > history.
> Ultimately, the contract is that (string)$foo->getMessage() won't > error, which is ... kind of useful, I guess? >
Totally, you got it right I think. Does the RFC trigger any other comments? Is the patch OK to people that know the engine well? I'll open the vote on February 6th there are no objections. Thank you, Nicolas