Re: is_digits() and digits type

From: Date: Tue, 12 May 2015 19:57:33 +0000
Subject: Re: is_digits() and digits type
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-86178@lists.php.net to get a copy of this message
On 12 May 2015 20:27:08 BST, Lester Caine <lester@lsces.co.uk> wrote: >On 12/05/15 19:55, Rowan Collins wrote: >> For instance, valid input for a 64-bit signed integer in a database >could include: >> - any PHP native integer (assuming nobody builds with 128-bit ints!) >> - any string consisting of all digits, such that when interpreted as >an integer the value won't exceed 2^64-1 >> - any string consisting of a '-' followed by digits, such that the >magnitude of the integer interpretation wouldn't exceed 2^64 >> - any PHP float with no fractional part, maybe capped to a magnitude >less than 2^53 for safety > >BUT >In INTEGER in a database is 32 bit and will remain 32 bit, just as >SMALLINT is 16 bit ... 64 bit is BIGINT and so the whole concept of >simply ignoring 32 bit and handling them instead as 64bit is wrong! Nobody is "ignoring 32-bit". If you want to validate that a variable will fit in a 32-bit signed integer, or a 16-bit unsigned one, or whatever else, you need to range-check it as above. Just as you would validate a variable which you expected to contain an email address before you used it in an SMTP header. Type hints are not intended for validating data that is entering or leaving PHP from or to other systems, they are only relevant when passing data from one part of a PHP system to another. On any given install of PHP, two libraries communicating with each other by function calls will agree on a definition of "int", because they are in the same process, and that is all that is needed for an "int" type hint to be meaningful. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#86178) next »