note 56677 added to function.ctype-digit

From: Date: Mon, 12 Sep 2005 10:05:27 +0000
Subject: note 56677 added to function.ctype-digit
Groups: php.notes 
Request: Send a blank email to php-notes+get-95041@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.ctype-digit.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56677 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56677&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56677&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56677&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56677&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56677&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56677&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56677&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#95041) next »