I am quite new to Yii and PHP, and I've just seen a behaviour which I think isn't normal, that's why I've posted into the "Bug discussion category".
Also just so you know I've spent quite some time (hours) trying to debug this and searching on internet, but couldn't find anything (unless it's my english, as it's not my mother language...)
So in my Yii project, when I retrieve a CActiveRecord from the database, all the attributes of the Model I get are strings even if some columns are defined as int.
Example :
$user = Users::model()->findByPk(1); var_dump($user->id)
This gives :
string(1) "1"
Is it normal that I get a "string" back from the database where the column was defined as "int" and the CActiveRecord "id" property has been generated by Gii as an Integer ?
I know PHP is dynamically typed but I would have expected Yii to cast the values retrieved from the database to the correct type, or am I missing something ?
I'm asking this because as I was assuming that the types were kept when retrieving models from the database, in my code I was comparing an id which I thought was a number to the number 2 using === and that was returning false...
if ($user->id === 2) // returns false even if the user id is 2 in the database !
If the behaviour I'm seeing is correct, then what's the best approach when comparing model's attributes to some values, using "==" instead of "===", or still using "===" but forcing the type of the attribute I'm comparing ?
Thanks in advance for your help.
My configuration (sorry I can't put the versions I'm using as I'm posting from work) :
- Mac OS Lion
- Apache
- Safari
- MySQL

Help












