Hi Walter,

On Fri, May 15, 2015 at 2:49 AM, Walter Parker <walt...@gmail.com> wrote:

> Adding a numeric pseudo type will not fix abuse, it will only change the
> abuse. I don't think it is worth the effort. I also think it might a
> slippery slope to lots of other pseudo types and other half ideas that will
> add complexity to the language without much in the way of benefit.
>

Pseudo type is not abuse if it's there.
Almost all PHP programs treated external values as string. PHP handled it
somewhat nicely by type juggling.

In PHP, integer like values are treated

signed 32 bit int:  32 bit CPU
signed 53 bit int:  32/64 bit CPU (IEEE 754 double)
signed 64 bit int:  64 bit CPU
arbitrarily int: 32/64 bit CPU (string digits is good enough for
databases/etc IDs)

If arithmetic is needed, we could assume it has at least signed 53 bit int.
If arithmetic is not needed, we could assume
arbitrarily int. I usually don't need integer arithmetic correctness much
because most arithmetic are very
simple. Examples are adding/subtracting date, stock, counter which will
never exceeds signed 53 bit int range.

On contrast, I need strict correctness for record IDs. Valid IDs should
never raise error/exception.

Use of type "int" type hint reduces reliable range to signed 32 bit int.

The mixing of types, casts and validations can cause problems. I don't see
> how adding pseudo types will actually fix this as this appears to a
> validation problem and not a typing problem.
>

Validations should not cause problems. If it does, the way validating data
is wrong.

I understand what's wrong with "int" type hints, yet I have to fight
against temptation
using it when signed 64 bit int is enough for my code/system. Vast majority
of
PHP programmers would use "int" type hint without considering the
limitation and
consequence.

Anyway, we need at least numeric value validation (safe cast) function.
Without it,
strict_types=1 is harmful especially because people will just use casts
which hides
problem is their code.

I don't expect PHP's "int" type hint accept arbitrarily numbers even when
GMP int
is fully integrated. PHP is made for web and interaction. JSON supports
"numeric"
that has undefined(unlimited) precisions, databases support huge numbers.
Advocating
users to use "string" type hint for these seems impossible. We'll see the
result soon.

Regards,

--
Yasuo Ohgaki
yohg...@ohgaki.net

Reply via email to