php - Cast as int or leave as string? -


i'm wondering if there reason cast variable, returned mysql string, int. i'm updating code , netbeans wants me use === instead of ==. problem === cares content type.

i had: if($user['user_state']==1){...}

so change this: if($user['user_state']==="1"){...}

or can this: if((int)$user['user_state']===1){...}

it doesn't make difference me if i've got int or str. won't doing math particular variable. , since i'll have rewrite conditionals in case, i'd rather right way.

so, think question best practice? or 1 of wonderful questions answers end happy marriages single vs double quotes?

the underlying reason netbeans suggest such thing this:

"1abc" == 1 // true 

strengthening comparison applying (int) cast , using === satisfy editor , purists, since typically trust database schema, above cast won't necessary , can use loose comparison instead.

to sum up, although strict comparisons practice in general it's considered overzealous when working external data such databases , (to lesser extent) posted data.

that said, still leaves matter of making netbeans ignore these "issues" in sensible way; having special instructions littered in code not great situation either.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -