Re: confused: casting a variable to integer
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: confused: casting a variable to integer

From: Justin Koivisto <justin@koivi.com>
Date: Tue Nov 29 2005 - 21:34:53 CET

Sean wrote:
> See the differece if you use ===
>
> <?
> $name="henk";
>
> echo "\$name=$name <br>";
> echo "(int)\$name=".(int)$name."<br>";
>
> if ($name === (int)$name){
> echo "equal";
> } else {
> echo "Not equal";
> }
>
> ?>
>
> http://php.net/operators.comparison
>

But be careful with this...

$i="4";
if($i === intval($i)){
    // this will not happen
}

Also keep in mind that values that are supplied via _GET, _POST, _COOKIE
are strings, not their representative types...

Therefore:

call page: page.php?i=4
if($_GET['i'] === intval($_GET['i'])){
    // this will not happen
}

-- 
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com
Received on Sat Dec 3 04:24:26 2005