note 85173 added to language.types.integer
| From: | dbmuller at gmail dot com | Date: | Mon, 18 Aug 2008 23:43:57 +0000 |
| Subject: | note 85173 added to language.types.integer | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143611@lists.php.net to get a copy of this message | ||
be careful relying on PHP's data type handling. I have a class that handles database calls and
in there a function to handle types and formatting them for insertion.
<?php
case constants::int:
$returnString = ($valueString >= 0) ? $valueString : "null";
break;
?>
Will evaluate to false if a user enters "0" since PHP thinks that the 0 is a Boolean. The
following code fixes it:
<?php
case constants::int:
$returnString = ((int)$valueString >= 0) ? (int)$valueString : "null";
break;
?>
----
Server IP: 117.104.160.194
Probable Submitter: 122.109.109.104
----
Manual Page -- http://www.php.net/manual/en/language.types.integer.php
Edit -- https://master.php.net/note/edit/85173
Del: integrated -- https://master.php.net/note/delete/85173/integrated
Del: useless -- https://master.php.net/note/delete/85173/useless
Del: bad code -- https://master.php.net/note/delete/85173/bad+code
Del: spam -- https://master.php.net/note/delete/85173/spam
Del: non-english -- https://master.php.net/note/delete/85173/non-english
Del: in docs -- https://master.php.net/note/delete/85173/in+docs
Del: other reasons-- https://master.php.net/note/delete/85173
Reject -- https://master.php.net/note/reject/85173
Search -- https://master.php.net/manage/user-notes.php