On 3/8/2017 11:24 PM, Andrey Andreev wrote: > Hi again, > > On Wed, Mar 8, 2017 at 9:39 PM, Rowan Collins <rowan.coll...@gmail.com> wrote: >> >> I think it comes down to what you're trying to achieve: the language can't >> have pseudo-types for every possible combination of types, so if you want to >> detect integers as one case, and other things that can be converted to >> string as another, just perform your checks in the right order: >> >> if ( is_int($foo) ) { >> // ... >> } elseif ( is_stringable($foo) ) { >> // ... >> } >> > > This is why I was concerned about the discussion becoming too broad - > it brings us (or me anyway) back to square 1, if not even out of > bounds. I wanted the ability to do "string or string object" checks > without multiple function calls, and now the suggested solution > doesn't do that. > > I do agree that we can't have pseudo-types for everything, but can we > at least have meaningful ones? How would "stringable" be different to > "string", and what's the point of either of them if they accept every > other scalar type? We're having this discussion because outside of the > so called "strict mode", PHP's string type is just as meaningful as > "scalar", which makes it useless IMO. > > Cheers, > Andrey. >
What is the use case where every other scalar (and null) type is not acceptable? I defended that stringable should bridge only string and objects with __toString too first, but after thinking more about it, there is no real world reason why one would need that. Almost all use cases I can think about evolve around strict mode and some function that simply does not care what it was. Hence, stringable would truly act like the into trait in Rust. Although, to be fair, Rust does not provide Into<String> nor Into<&'a str> for numeric types. I actually don't know why, since fmt::Display is implemented for all of them. Then again, Rust is very, very different to PHP. -- Richard "Fleshgrinder" Fussenegger -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php