Re: [RFC] Permit trailing whitespace in numeric strings
| From: | Claude Pache | Date: | Wed, 27 Mar 2019 14:26:44 +0000 |
| Subject: | Re: [RFC] Permit trailing whitespace in numeric strings | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-104966@lists.php.net to get a copy of this message | ||
> Le 27 mars 2019 à 14:29, Benjamin Morel <benjamin.morel@gmail.com> a écrit :
>
> Thinking about this a bit more, what about following JavaScript semantics? I find them really
> good in this respect:
>
Arithmetic in JavaScript cannot be used reliably (in general) without converting your data to the
proper type, because 1 + 1 gives you 11 if one of the 1s is encoded as string. PHP does a better job
in that respect. As a result, there is good chance that people (it is at least the case for me) are
more confident to rely (often implicitly) on automatic type conversion between strings and numbers
when doing basic arithmetic in PHP than in JS, including for comparison of numeric values.
About leading/trailing whitespaces: usually, numbers encoded as strings do not contain them; so that
it may be OK to consider strings containing them as non-numeric if we want.
—Claude