RE: [PHP] Comparison Operator
| From: | Richard Lynch | Date: | Mon, 10 Jan 2005 23:51:44 +0000 |
| Subject: | RE: [PHP] Comparison Operator | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-206039@lists.php.net to get a copy of this message | ||
Chadwick, Russell wrote:
>
> The function this is from sometimes uses $_POST or $_GET input, so
> sometimes its comparing 1337 with '1337' and === would break that.
>
> so I'll have to use something like:
>
> if (($value == $curval) && !(is_string ($curval) && ($value == 0)))
>
> unless there is a better way
Hard to say, without knowing what the function is, what it's supposed to
do, who's calling it and why/when/where...
I'll take a wild stab at it, though, and suggest that if you care about
data types that much, then you should be converting your $_GET/$_POST to
(int) in the first place.
Plus, you should be converting your $_GET/$_POST data to (int) when
appropriate for your data scrubbing (security).
So, really, you should have:
<?php
$curval = (int) (isset($_GET['curval']) ? $_GET['curval'] : 0);
...
your_function(1337, $curval);
...
?>
Then you can use === in your function safely.
--
Like Music?
http://l-i-e.com/artists.htm