RE: [PHP-DEV] Coercive Scalar Type Hints RFC
| From: | Zeev Suraski | Date: | Sat, 21 Feb 2015 21:02:37 +0000 |
| Subject: | RE: [PHP-DEV] Coercive Scalar Type Hints RFC | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-83428@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Pádraic Brady [mailto:padraic.brady@gmail.com]
> Sent: Saturday, February 21, 2015 9:56 PM
> To: Zeev Suraski
> Cc: Anthony Ferrara; PHP internals
> Subject: Re: [PHP-DEV] Coercive Scalar Type Hints RFC
>
>
> The sentence stresses garbage in too much to read as accurate. To clarify,
> there is a) garbage in due to weak coercion and b) a function being called
> with a string when the typehint says int. Both are separate concerns
> around
> error detection. Stricter coercion can enable only one of these two, for
> example. That's better than neither, of course! The coercion rules were
> stricter than I expected based on previous emails. Stressing one too much
> might suggest to a reader that the second concern does not exist.
As I told Anthony, based on what I saw on the list, the former appeared to
be a much more widely-held concern than the latter.
> Other pedantic comment: "numerous" is probably too strong a word there.
> The advantages may vary by person, but usually fit within basic
> five-finger
> math. It would be more important to enumerate them rather than selecting
> one as primary.
Thanks, changed to 'several'. Double thanks, as I always thought 'Numerous'
was more or less equivalent to 'Several', and you made me look it up :)
> On the RFC rules themselves, a few comments:
>
> 1. Happy to see leading/trailing spaces excluded.
Happy to see you happy!
> 2. Rules don't make mention of leading zeroes, e.g. 0003 3. "1E07" might
> be
> construed as overly generous assuming we are excluding stringy integers
> like
> hex, oct and binary 4. I'm assuming the stringy ints are rejected?
It's up for discussion. I personally don't have very strong feelings on how
we deal with these cases, as the main thing I care about is for the common
cases to work. That said, if it was entirely up to me, I'd accept "0003"
but not "1E07" - as the latter is considered floating point:
$x = "1e7";
print gettype($x+0); // would print double
But if rejecting leading zeros is what's needed to get a lot more people to
support it, I can live with that.
> 5. Is ".32" coerced to float or only "0.32"? Merely for clarification.
With the same disclaimer as the one for the previous answer, I'd go with
accepting ".32" in the same way is_numeric() accepts it.
> 7. In string to float, only capital E or also small e?
I think both, same is_numeric() rationale - same disclaimer.
> 8. I'll never stop call them "stringy" ints.
I can live with that :)
Thanks for the feedback!
Zeev