type casting to float to "ensure reliable comparison" ?
From: maxim vexler
Date: 08/07/04
- Next message: Bill H: "Spell Checking."
- Previous message: lawrence: "how to change the username that PHP runs as?"
- Next in thread: Chung Leong: "Re: type casting to float to "ensure reliable comparison" ?"
- Reply: Chung Leong: "Re: type casting to float to "ensure reliable comparison" ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 07 Aug 2004 20:17:22 +0000
in a book i am ready now : O'Reilly - Web Database Application with PHP
and MySQL, 2nd ed. by David Lane, Hugh E. Williams
on chapter 9 the author give an example for age validation :
(simplified code, not a direct quote)
$dob = mktime(0,0,0, 5, 3, 1983);
if ((float)$dob > (float)strtotime("-18years"))
{
print "....";
return false;
}
my question is why the type casting to float ?
after all the return type of both mktime & strtotime is int, why the
need to cast to float?
the authors emphasize this in the explanation section by "We use the
mktime() function to convert the date of birth to a large numeric Unix
timestamp value, and the strtotime() function to discover the timestamp
of exactly 18 ago. *Both are cast to a large floating number to ensure
reliable comparison...*"
thank you for comment's ohh & yes - hope I'm not breaking any copyright
lows :).
- Next message: Bill H: "Spell Checking."
- Previous message: lawrence: "how to change the username that PHP runs as?"
- Next in thread: Chung Leong: "Re: type casting to float to "ensure reliable comparison" ?"
- Reply: Chung Leong: "Re: type casting to float to "ensure reliable comparison" ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|