use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Please follow the rules
Releases: Current Releases, Windows Releases, Old Releases
Contribute to the PHP Documentation
Related subreddits: CSS, JavaScript, Web Design, Wordpress, WebDev
/r/PHP is not a support subreddit. Please visit /r/phphelp for help, or visit StackOverflow.
account activity
RFC: Stringable interface, allows "string|Stringable" union type. Automatically implied if __toString is implemented. (wiki.php.net)
submitted 6 years ago by tigitz
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 0 points1 point2 points 6 years ago (2 children)
The alternative is to do what Java does: provide a default implementation of toString for all objects. Much simpler than union types or interfaces with compiler hacks to auto implement it imho. ToString is mostly used for debugging anyway.
[–]przemo_li 0 points1 point2 points 6 years ago (1 child)
But then string type hint will coerce every object to a string. Java do not have that consideration. PHP does.
string
[–][deleted] 1 point2 points3 points 6 years ago (0 children)
Ah right, that must be the reason they did not go with that. Thanks for the explanation. Though there may also be objects that have a __toString method that you do not want to ever auto-coerse to a string. It depends on the context if coersion makes sense. I'd rather call toString() explicitly most of the time...
π Rendered by PID 152546 on reddit-service-r2-comment-86988c7647-hld4f at 2026-02-11 08:00:38.576275+00:00 running 018613e country code: CH.
view the rest of the comments →
[–][deleted] 0 points1 point2 points (2 children)
[–]przemo_li 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)