note 110747 added to function.ctype-digit
| From: | Joni | Date: | Fri, 30 Nov 2012 18:44:34 +0000 |
| Subject: | note 110747 added to function.ctype-digit | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192236@lists.php.net to get a copy of this message | ||
A simple fix to make sure that integers are always treated as strings - to avoid unexpected results.
Just add double quotes around your variable.
<?php
ctype_digit(5); // false
ctype_digit(48); // true
ctype_digit(255); // false
ctype_digit(256); // true
ctype_digit("5"); // true
ctype_digit("48"); // true
ctype_digit("255"); // true
ctype_digit("256"); // true
$integer = 5;
ctype_digit($integer); // false
ctype_digit("$integer"); // true !
?>
----
Server IP: 69.147.83.199
Probable Submitter: 89.173.133.74
----
Manual Page -- http://www.php.net/manual/en/function.ctype-digit.php
Edit -- https://master.php.net/note/edit/110747
Del: integrated -- https://master.php.net/note/delete/110747/integrated
Del: useless -- https://master.php.net/note/delete/110747/useless
Del: bad code -- https://master.php.net/note/delete/110747/bad+code
Del: spam -- https://master.php.net/note/delete/110747/spam
Del: non-english -- https://master.php.net/note/delete/110747/non-english
Del: in docs -- https://master.php.net/note/delete/110747/in+docs
Del: other reasons-- https://master.php.net/note/delete/110747
Reject -- https://master.php.net/note/reject/110747
Search -- https://master.php.net/manage/user-notes.php