php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #23158 a new digit checker
Submitted: 2003-04-10 17:31 UTC Modified: 2011-01-01 20:43 UTC
Votes:4
Avg. Score:1.8 ± 0.8
Reproduced:0 of 3 (0.0%)
From: melkor at dance dot student dot utwente dot nl Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5CVS-2003-04-10 (dev) OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: melkor at dance dot student dot utwente dot nl
New email:
PHP Version: OS:

 

 [2003-04-10 17:31 UTC] 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)).. 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-31 22:49 UTC] michael at chunkycow dot com dot au
This is bogus, ctype_digit(4500) returns true.
 [2011-01-01 20:43 UTC] jani@php.net
-Status: Open +Status: Bogus -Package: Feature/Change Request +Package: *General Issues
 [2011-01-01 20:43 UTC] jani@php.net
See above.
 [2012-04-04 18:35 UTC] lenar at city dot ee
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 13:01:33 2025 UTC