Hi David, On Fri, May 15, 2015 at 2:12 PM, David Muir <davidkm...@gmail.com> wrote:
> I still don’t see how you can put the blame for the unhanded exception on > type hints. The problem you’re describing is not new and exists today with > libraries using code like this: > > function foo($int) { > if(!is_int($int)) { > throw new InvalidArgumentException(‘Parameter must be of type > int’); > } > //… do something with $int > } > Thoughtful/careful programmers will not have problems. Programmers who assume old behavior with "int" hint will. Sorry that I created scattered threads. I thought is_digists()/digits hint might be useful. Anyway it's from the other thread. 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 exceed signed 53 bit int range. In 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. We should have big warning in the manual so that users will not have wrong assumption. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net