当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Yii: model attributes don't preserve types?

问题描述:

I was very surprised to discover that gettype($myModel->id) == 'string' for a model with an integer id field in the underlying MySQL DB.

This looks completely wrong. Does it really work this way? If yes, why? Otherwise, all ideas about how could this happen are welcome.

网友答案:

As far as I know Yii just assigns the values it gets from PDO, so it probably must be a PDO thing. Tbh, I don't really rely on the actual variable types in PHP, as it is a soft-typed language anyway and that could be dangerous. Imo it's better to call "is_numeric" than check the actual type of a variable for instance.

网友答案:

Here you have some kind of explanation from Yii forum:

This is by design and already discussed few times on the forum... problem is that database values can hold bigger numbers than PHP values so a string is used.

分享给朋友:
您可能感兴趣的文章:
随机阅读: