Hi Andrey,

I think this is an interesting area to explore, but do think the scope needs to 
be widened slightly.


On 8 March 2017 12:25:54 GMT+00:00, Andrey Andreev <n...@devilix.net> wrote:
>I ultimately wouldn't care if it's a separate function and did in fact
>think of an is_stringable() function, but wasn't happy with the naming
>- who's to say that e.g. integers aren't stringable? Bar
>horribly-verbose names like
>"string_or_objects_implementing__toString", I don't think there's a
>way to avoid that ambiguity. :/
>If we want a "stringable" type though

Sometimes, the fact that you can't think of a good name for a function is a 
clue that the function isn't solving a well-defined problem.

In this case, why *wouldn't* the function return true for integers? If the 
question the function is asking is "can this value be cast to string?" then the 
answer for any integer should be "yes". If the question is "will it pass a 
strict type check as a string", then the answer for objects would always be 
"no". Am I missing a situation where casting an object would be safe, but 
casting an integer wouldn't?

My own thought, mentioned somewhere in the long debate about scalar type hints, 
was to have a "can be cast to" function, which basically predicts if a *weak* 
type hint would accept the value without errors or warnings. This would work 
for stringable objects, but also for numeric strings, etc.

Regards,

-- 
Rowan Collins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to