Edit report at https://bugs.php.net/bug.php?id=23158&edit=1
ID: 23158 Comment by: lenar at city dot ee Reported by: melkor at dance dot student dot utwente dot nl Summary: a new digit checker Status: Not a bug Type: Feature/Change Request Package: *General Issues Operating System: linux PHP Version: 5CVS-2003-04-10 (dev) Block user comment: N Private report: N New Comment: ctype_digit() is actually partly bogus suggestion because of the behavior it has in the range -128 ... 255 if integer is passed. So ctype_digit(100) returns false. I can understand the reasoning in this case (replicate C API of ctype* functions) but it also means that is_digit() or similar is kind of warranted and would be a better fit for the dynamically typed world of PHP. Previous Comments: ------------------------------------------------------------------------ [2011-01-01 20:43:14] j...@php.net See above. ------------------------------------------------------------------------ [2007-12-31 22:49:29] michael at chunkycow dot com dot au This is bogus, ctype_digit(4500) returns true. ------------------------------------------------------------------------ [2003-04-10 17:31:15] melkor at dance dot student dot utwente dot nl For ID's in databases, a simple is_digit($mixed) check would be nice. is_numeric($mixed) also accepts 1.0E10 and such values, which are not valid for integer database IDs. ctype_digit($string) returns false for any integer it gets, because ctype_digit(4500) gets translated to isdigit(4500) which of course is not a valid ascii character at all. This might seem a little far fetched, but lots and lots of code uses is_numeric checks where they should not. I do this too, because otherwise I need 2 checks (is_integer($var) || ctype_digit($var)).. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=23158&edit=1