View Single Post
Old 09-20-2010, 05:15 PM  
Tempest
Too lazy to set a custom title
 
Industry Role:
Join Date: May 2004
Location: West Coast, Canada.
Posts: 10,217
Quote:
Originally Posted by BestXXXPorn View Post
Ouch... no don't do that and if you really must typecast instead use

$val = intval($_POST['variable']);

And always use single quotes unless you need special escaped chars... Every time you use double quotes for a string in PHP you cause the string interpreter to parse the entire string looking for variables, special chars, etc... Using single quotes instead ensures that doesn't happen...
Agreed with the single quotes.. Far too much code out there that uses double quotes.

As for the int thing, let's all argue about how best to handle them lol...

I actually do a preg_match on all values that are supposed to be pure integers so I can catch invalid data. i.e.:

preg_match('/^[+-]?\d+$/', (string)$value)
Tempest is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote