【Background of the project】
Recently doing a restful style of the project, we found json data tables returned id is always the string type, but another table id is always int. I.e., the data types are returned.
[The Reason]
In yii \ getColumnPhpType function db \ Schema class, this function determines the type out of the final data, as follows:
/** * Extracts the PHP type from abstract DB type. * @param ColumnSchema $column the column schema information * @return string PHP type name */ protected function getColumnPhpType($column) { static $typeMap = [ // abstract type => php type self::TYPE_TINYINT => 'integer', self::TYPE_SMALLINT => 'integer', self::TYPE_INTEGER => 'integer', self::TYPE_BIGINT => 'integer', self::TYPE_BOOLEAN => 'boolean', self::TYPE_FLOAT => 'double', self::TYPE_DOUBLE => 'double', self::TYPE_BINARY => 'resource', self::TYPE_JSON => 'array', ]; if (isset($typeMap[$column->type])) { if ($column->type === 'bigint') { return PHP_INT_SIZE === 8 && !$column->unsigned ? 'integer' : 'string';-> type === 'Integer'$ column(ELSEIF }// field type determined here) { Return PHP_INT_SIZE ===. 4 && $ column ? -> unsigned 'String': 'Integer' ; // field type determined here } return $ typeMap [ $ column -> type]; } return 'String' ; }
Conclusion: If PHP_INT_SIZE DB table is 4 and the corresponding column is unsigned int, then returns the string type in accordance with the interpretation php.net:. PHP does not support unsigned integer.