php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45710 ctype_digit not validating int values
Submitted: 2008-08-04 23:14 UTC Modified: 2008-08-05 00:59 UTC
From: dragos at codersnest dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.1.6 OS: fedora 6
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: dragos at codersnest dot com
New email:
PHP Version: OS:

 

 [2008-08-04 23:14 UTC] 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"
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-05 00:52 UTC] 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-05 00:59 UTC] dragos at codersnest dot com
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?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC