Re: [Discussion] is_string(), string type and objects implementing __toString()
| From: | Fleshgrinder | Date: | Thu, 09 Mar 2017 17:37:42 +0000 |
| Subject: | Re: [Discussion] is_string(), string type and objects implementing __toString() | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98458@lists.php.net to get a copy of this message | ||
On 3/9/2017 3:18 AM, Stanislav Malyshev wrote:
> Hi!
>
>> I submitted a GitHub PR* to allow objects implementing __toString() to
>> *optionally* pass is_string() validation. More verbose wording of my
>> motivation can be seen in the PR description, but here are the main
>> points:
>
> I don't think it's right approach. is_* functions check the current type
> of the value, not whether it can be converted to another type. If we
> need ones that express the latter, we should have different functions.
>
> Also, as already noted, having __toString doesn't mean it returns
> something useful.
>
This is not true at all:
1. is_dir
2. is_executable
3. is_file
4. is_finite
5. is_infinite
6. is_link
7. is_nan
8. is_readable
9. is_resource (checks the resource's type too)
10. is_uploaded_file
11. is_writable
All other
is_* functions are either checking the type or the instance
of an object in some way.
--
Richard "Fleshgrinder" Fussenegger