Yii2 Integers

hi

for example my os is 64 bit. i have a table structure like :


CREATE TABLE `MyTable` (

  `col_int` int(11) NOT NULL,

  `col_bigint` bigint(20) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8;



when i fetch col_bigint with findOne method, yii2 return as string or int ?

i know in 32 bit os, yii2 return as string.

String for compatibility reasons.

You may use AttributeTypecastBehavior to change this behavior.

http://www.yiiframework.com/doc-2.0/yii-behaviors-attributetypecastbehavior.html

thanks.

i updated my yii2 to last version and use this behavior.

but i have a question.

i want detect overflow in type casting and throw a error for prevent this action.

how i can attach a function to this behavior for run before type casting ?

like :




public function behaviors()

    {

        return [

            'typecast' => [

                'class' => AttributeTypecastBehavior::className(),

                'attributeTypes' => [

                    'myColumn' => AttributeTypecastBehavior::TYPE_INTEGER,

                ],

                'typecastAfterFind' => true,

		'beforeTypeCast' => function($value){

			if(bccomp($value,(int)$value) !== 0)

				throw new \Exception('Overflow !');

			return (int)$value;

		},

            ],

        ];

    }






public function behaviors()

{

    return [

        'typecast' => [

            'class' => AttributeTypecastBehavior::className(),

            'attributeTypes' => [

                'myColumn' => function ($value) {

                    if (bccomp($value, (int)$value) !== 0) {

                        throw new \Exception('Overflow !');

                    }

                    return (int)$value;

                },

            ],

            'typecastAfterFind' => true,

        ],

    ];

}