CActiveRecord returns string attributes of the model

Hi guys,

I am relevantly new to this forum but I have just started using Yii. I have experience with CakePHP so it is relatively easy for me to get the hang of it. So let’s get straight to the point. I have this simple request:

$user = Users::model()->findByAttributes(array('username'=>$username), array('order'=>'id DESC'));

var_dump($user->id); // id is defined as INT in the database

So what I get is

string(1) "1" 

What is the reason for the model to return a string when the id is defined as an integer in the AR and furthermore how can I remedy this without typecasting because an easy workaround is:




Should I understand from the missing comments that this is a bug which has not been fixed and I have to typecast every time I need a part of a record from the DB?

Seems to be the case that this is string, not sure why.

But if you treat this attribute as integer somewhere, php will automatically cast. So there is no need to cast it manually. At least I don’t see a reason why you should do…

This has already been discussed few times on the forum, so maybe that is the reason you did not get any answer… here is one thread about this -