Re: [RFC-Discuss] Scalar Type Declarations v0.5
| From: | Christoph Becker | Date: | Thu, 19 Feb 2015 01:23:09 +0000 |
| Subject: | Re: [RFC-Discuss] Scalar Type Declarations v0.5 | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-83138@lists.php.net to get a copy of this message | ||
Anthony,
Anthony Ferrara wrote:
> On Wed, Feb 18, 2015 at 6:09 PM, Christoph Becker <cmbecker69@gmx.de> wrote:
>
>> Have you considered the overflow behavior of ints resulting in a float?
>> For instance, the following code would produce E_RECOVERABLE_ERROR, AIUI:
>>
>> <?php
>>
>> declare(strict_types=1);
>>
>> function foo(int a, int b) {
>> bar(a * b);
>> }
>>
>> function bar(int n) {
>> }
>>
>> foo(10000000000, 10000000000);
>
> That is a very good point. We had discussed that a while ago, but it
> hasn't come up in a while here. I've added a section in the RFC on it:
>
> https://wiki.php.net/rfc/scalar_type_hints_v5#integer_overflow_to_float_behavior
Thanks for adding a respective note to the RFC, because IMHO it's quite
important to consider the behavior. Somehow I would like to have
Scheme's numeric system, but that doesn't seem to fit well with type
hinting (neither strict nor weak) -- at least not when it's about
performance.
> Basically, I don't see any sane alternative but to have it cause an
> error at runtime. It's not precision loss, it's magnitude loss.
>
> The only other thing I can think of is to have the operators not
> promote in strict mode, but that's even worse since now you're
> clamping and not even giving the ability to detect it.
>
> I don't think in practice it will be a huge issue, but even if it
> comes up, it'll at least error sanely...
ACK.
--
Christoph M. Becker