#45710 [Bgs]: ctype_digit not validating int values
| From: | dragos at codersnest dot com | Date: | Tue, 05 Aug 2008 00:59:32 +0000 |
| Subject: | #45710 [Bgs]: ctype_digit not validating int values | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-127594@lists.php.net to get a copy of this message | ||
ID: 45710
User updated by: dragos at codersnest dot com
Reported By: dragos at codersnest dot com
Status: Bogus
Bug Type: Variables related
Operating System: fedora 6
PHP Version: 5.1.6
New Comment:
Actually it expects a string, I know that, but why wouldn't it say
"true" if I ask ctype_digit(65) ? Isn't 65 a valid number? Is every
character a decimal digit ? I guess there should be a cast there to
string for the input parameter, and then the bug would be fixed, don't
you?
Previous Comments:
------------------------------------------------------------------------
[2008-08-05 00:52:33] jani@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
The function expects a string as parameter. Integer does not need
chjecking if it's an integer.
------------------------------------------------------------------------
[2008-08-04 23:14:49] dragos at codersnest dot com
Description:
------------
When passing an integer to ctype_digit, it will fail validating it. I
tested several times, looks like this behaviour is consistent, I also
tried using ctype_digit(65) which will also return "false".
The PHP version is actually 5.1.6, running on Fedora 6 x86_64 with
Apache 2.2.6 , all installed from the Fedora Repository.
Same behaviour successfully reproduced with PHP 5.2.5 + Apache 2.0.54
on Suse9 x86_64.
Possibly somewhere when the parameter passed is cast to a string, the
value is somehow corrupted.
Reproduce code:
---------------
function getm($width, $height) {
$errors = array();
if (!ctype_digit($width) || (int)$width <=0 ) {
$errors[] = 'Width must be a positive integer value, ' .
gettype($width) . ' passed';
}
if (!ctype_digit($height) || (int)$height<=0 ) {
$errors[] = 'Height must be a positive integer value, ' .
gettype($height) . ' passed';
}
return $errors;
}
$a = getm(48, 65);
var_dump($a);
Expected result:
----------------
array (0) {}
Actual result:
--------------
array(1) {
[0]=>
string(55) "Height must be a positive integer value, integer passed"
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45710&edit=1