samedi 12 septembre 2015

Why should I write !== false instead of ==true?

I often see scripts testing if a variable is different from FALSE.

This is an example from php man of "fgetcsv" function, but I think I saw that on Java too.

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    //...
}

Even if it doesn't change much, it would seem more natural to go like :

while (($data = fgetcsv($handle, 1000, ",")) === TRUE) {
    //...
}

Is there a reason the second code is less logic or less efficient ?

Aucun commentaire:

Enregistrer un commentaire