开发者

Yii: model attributes don't preserve types?

开发者 https://www.devze.com 2023-02-07 05:45 出处:网络
I was 开发者_如何学JAVAvery surprised to discover that gettype($myModel->id) == \'string\' for a model with an integer id field in the underlying MySQL DB.

I was 开发者_如何学JAVAvery 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消