Re: [RFC] Scalar Type Hinting With Casts (re-opening)
| From: | Andrea Faulds | Date: | Wed, 16 Jul 2014 23:35:23 +0000 |
| Subject: | Re: [RFC] Scalar Type Hinting With Casts (re-opening) | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-75616@lists.php.net to get a copy of this message | ||
On 17 Jul 2014, at 00:18, Rowan Collins <rowan.collins@gmail.com> wrote:
> Now, I have no idea how ZPP actually works, and get lost in a maze of macros whenever I try to
> look at it, but evidently it has logic to distinguish, at least for string->int, three cases:
>
> 1) safe / lossless / well formed input (cast silently), e.g. '123' => int(123)
> 2) unsafe / lossy / non well formed (give a notice), 'e.g. '123abc' =>
> int(123)
> 3) impossible / inappropriate (from the point of view of the user, give a warning, and cause
> different behaviour of the function), e.g. 'abc' => int
zpp’s casts are (one form of) implicit cast. We actually do multiple different kinds of implicit
casts in different places with different results; “0xa” is variously an integer and not an
integer, depending on context, because nobody seems to have made their mind up whether
is_numeric_string or strtol is used to parse numeric strings. :(
The only casts that are explicit are using (int) and friends, or intval() and friends (I believe the
two are equivalent).
--
Andrea Faulds
http://ajf.me/