Anthony,

Anthony Ferrara wrote:

> On Wed, Feb 18, 2015 at 6:09 PM, Christoph Becker <cmbecke...@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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to