Re: [Discussion] is_string(), string type andobjectsimplementing __toString()
| From: | Andrey Andreev | Date: | Wed, 08 Mar 2017 22:42:34 +0000 |
| Subject: | Re: [Discussion] is_string(), string type andobjectsimplementing __toString() | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98445@lists.php.net to get a copy of this message | ||
Hi Andrea,
On Wed, Mar 8, 2017 at 8:44 PM, Andrea Faulds <ajf@ajf.me> wrote:
> Fleshgrinder wrote:
>>
>> On 3/8/2017 7:36 PM, Andrea Faulds wrote:
>>>
>>> Hi,
>>>
>>> Andrey Andreev wrote:
>>>>
>>>> The question is rather "is this value a string?", only with the added
>>>> assumption that __toString() objects are treated as "string objects"
>>>> and thus fulfill the condition (another reason why I went for an
>>>> is_string() parameter).
>>>
>>>
>>> This is a faulty assumption. The presence of __toString() doesn't mean
>>> the object is a string, or intended to be used like one.
>>>
>>
>> What is it then in your book?
>>
>
> It means the object can be converted to a string. But such a conversion may
> entail a loss of information and not be equivalent to the object itself. It
> might be a “human-readable” form, for instance.
>
There will be loss of information most of the time, indeed. That's not
the point; broadly speaking, you'd have to alias __toString() to
serialize() in order to avoid that.
If it has an explicitly declared string representation, I want to have
the option to use that easily, without writing boilerplate code to
filter-out every other type.
Cheers,
Andrey.