note 56677 deleted from function.ctype-digit by colder
| From: | colder@php.net | Date: | Fri, 23 Feb 2007 12:34:38 +0000 |
| Subject: | note 56677 deleted from function.ctype-digit by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-123759@lists.php.net to get a copy of this message | ||
Note Submitter: crimson at technologist dot com
----
In PHP 4.3.11 (not sure about other versions), this function can provide erratic behavior. Though we
normally expect automatic type casting to do the work for us, in these ctype functions, you must do
it yourself!
Example:
<?php
echo '<pre>';
$fields[0] = 'somestring';
$fields[1] = 150679;
$fields[2] = 20050912;
var_dump($fields);
if(!ctype_digit($fields[1])) echo "1 not digits\n";
if(!ctype_digit($fields[2])) echo "2 not digits\n";
var_dump($fields);
echo '</pre>';
?>
Returns:
array(3) {
[0]=>
string(10) "somestring"
[1]=>
int(150679)
[2]=>
int(20050912)
}
array(3) {
[0]=>
string(10) "somestring"
[1]=>
string(8) "20050912"
[2]=>
int(20050912)
}
Notice that the value in $fields[2] was converted to a string and moved to $fields[1]! Explicitly
converting the values to strings solved the problem.