On Wed, 22 Jan 2020 at 15:47, Nicolas Grekas <nicolas.grekas+...@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?

Regards,
-- 
Rowan Tommins
[IMSoP]

Reply via email to