note 85173 deleted from language.types.integer by googleguy
| From: | googleguy@php.net | Date: | Sat, 19 Jan 2013 03:45:06 +0000 |
| Subject: | note 85173 deleted from language.types.integer by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193238@lists.php.net to get a copy of this message | ||
Note Submitter: dbmuller at gmail dot com
----
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;
?>