dimanche 8 novembre 2015

php - compare years with different data types

I found that ?year=2015 works on my website, the same way, ?year=2015sjkhdkfzgsfkzgsk does, when this 'year' is compared to the integer value from the database (MySQL YEAR type), somehow like this:

$year = Input::get('year');
$dbyear = Pic::find($id)->value('year');
if($year == $dbyear){
    //..
}

because this seems to return true:

var_dump(2015 == '2015abcdefg34748fhhdfgxfgfg');

Is this normal or possibly a bug? How can I better compare these values? Now I am doing:

$year = substr(Input::get('year'),0,4);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire