Add Stringable interface#5083
Conversation
fc39453 to
8b15e23
Compare
|
Can I ask why you don't also support other types that can be cast to a string? e.g. everything but arrays and object that don't have |
I'm sorry I totally miss your question. There is no such thing as "supporting other types". |
|
@ntzm |
d7a345c to
52d1736
Compare
Is there any reason to keep the magic method |
of course there is: we want to be sure, from a type pov, that the object implements the casting magic method. |
|
But for example |
5d9cb20 to
75eae57
Compare
75eae57 to
4e344b1
Compare
I think I don't understand your question. I have a few ideas about what you may mean but can't decide which one is the good one. Can you give examples of what you mean? Or more details, please? |
|
Sure, I mean something like interface Stringable
{
function toString(): string;
}seems this also solves the issue with return type and BC. |
aa675c5 to
0789a35
Compare
|
Is there an RFC for this. Maybe pose the two options for a vote, with three choices. No interface, option one, option two? |
|
@GrahamCampbell it's way too early to think about voting options. There has been very little discussion on the matter, and there has been none on php-internals, which is still the only official way AFAIK. |
a398abd to
971ec86
Compare
dc13404 to
979e609
Compare
|
Just as a heads up, I rebased and force pushed. Regarding the automatic implementation of Which would be legal if |
|
Thanks for the heads up.
how do we achieve this? in zend_compile.c? Did you give it a try? |
|
@nicolas-grekas I pushed a new commit that should do it for user classes. |
|
Great, thank you! I'm going to update the RFC then. |
f4891e2 to
d95c60a
Compare
|
PR rebased to fix some conflicts reported by GitHub. RFC updated to mention that the interface is added automatically once __toString is found. |
|
Vote is now open btw: https://wiki.php.net/rfc/stringable |
b88af93 to
f815dd2
Compare
|
@nikic Now that the RFC has been accepted, would you mind merging this PR, please? (or someone else with merge right?) Or do I need to do anything else before? |
|
@nicolas-grekas I granted you php-src karma so you can merge it yourself[1], see the wiki here[2] for merging from Github. It should take about 15min or so tops for these new karma rights to syncronize. [1] http://svn.php.net/viewvc?view=revision&revision=349278 |
f815dd2 to
336eb48
Compare
|
Thanks @KalleZ. Thank you everyone for the feedback here! |
> Added Stringable interface, which is automatically implemented if a class defines a __toString() method. Refs: * https://wiki.php.net/rfc/stringable * php/php-src#5083 * php/php-src@336eb48
RFC at https://wiki.php.net/rfc/stringable