{"record":{"id":"529d005998bfde90","repo":"yiisoft/yii2","slug":"unsupported-type-type","errorCode":null,"errorMessage":"Unsupported type '{type}'","messagePattern":"Unsupported type '(.+?)'","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/behaviors/AttributeTypecastBehavior.php","lineNumber":282,"sourceCode":"                case self::TYPE_FLOAT:\n                    return (float) $value;\n                case self::TYPE_BOOLEAN:\n                    return (bool) $value;\n                case self::TYPE_STRING:\n                    if (is_float($value)) {\n                        return StringHelper::floatToString($value);\n                    }\n                    return (string) $value;\n            }\n\n            if (PHP_VERSION_ID >= 80100 && is_subclass_of($type, \\BackedEnum::class)) {\n                if ($value instanceof $type) {\n                    return $value;\n                }\n                return $type::from($value);\n            }\n\n            throw new InvalidArgumentException(\"Unsupported type '{$type}'\");\n        }\n\n        return call_user_func($type, $value);\n    }\n\n    /**\n     * Composes default value for [[attributeTypes]] from the owner validation rules.\n     *\n     * Validators that have a [[\\yii\\validators\\Validator::$when|when]] condition are ignored: the detection\n     * result is composed once per owner class, while such a condition can only be resolved against a particular\n     * model instance at validation time. Type-casting an attribute whose rule may not even be applied would\n     * convert a value that has never been validated, so attributes covered by conditional rules only are left\n     * out of the map. Specify [[attributeTypes]] explicitly if you need them to be type-casted.\n     *\n     * @return array attribute type map.\n     */\n    protected function detectAttributeTypes()\n    {","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/behaviors/AttributeTypecastBehavior.php#L264-L300","documentation":"Thrown by AttributeTypecastBehavior::typecastValue() when $type is a scalar (string) that matches none of the supported type names — 'integer', 'float', 'boolean', 'string' (the class TYPE_* constants) — and, on PHP 8.1+, is not the class name of a BackedEnum subclass. Any other scalar type string is rejected; non-scalar types are treated as callables and dispatched via call_user_func() instead.","triggerScenarios":"Configuring attributeTypes with shorthand names like 'int', 'bool', 'double' (only 'float' is accepted, 'double' is not in the switch) or custom labels like 'timestamp'; using a class-string of a unit enum or a non-backed enum on PHP 8.1+; referencing an enum FQCN while running PHP < 8.1 where the enum branch is compiled out; a typo in the type constant.","commonSituations":"Copy-pasting type names from Doctrine/PHPDoc annotations ('int', 'bool') into attributeTypes; upgrading to enum-based casting with enums that are not backed; environments differing in PHP version so the enum path silently disappears; mixing callable types (fine) with invented string type names (throws).","solutions":["Use only the supported names or, better, the class constants: AttributeTypecastBehavior::TYPE_INTEGER, TYPE_FLOAT, TYPE_BOOLEAN, TYPE_STRING.","For custom conversions, pass a callable instead of a string: 'attributeTypes' => ['status' => fn($v) => (int) $v].","For enum casting, use a backed enum (enum Status: string) on PHP 8.1+ and give its FQCN as the type.","Check for typos/shorthands ('int', 'bool', 'double') in the attributeTypes config."],"exampleFix":"// before\n'attributeTypes' => [\n    'count' => 'int',        // unsupported shorthand\n    'active' => 'bool',      // unsupported shorthand\n    'status' => 'StatusEnum', // unit enum (not backed) -> also unsupported\n],\n\n// after\n'attributeTypes' => [\n    'count' => AttributeTypecastBehavior::TYPE_INTEGER,\n    'active' => AttributeTypecastBehavior::TYPE_BOOLEAN,\n    'status' => StatusEnum::class, // enum Status: int { ... } (backed, PHP 8.1+)\n],","handlingStrategy":"validation","validationCode":"$allowed = ['integer', 'float', 'boolean', 'string'];\n$isEnumType = PHP_VERSION_ID >= 80100 && is_string($type) && is_subclass_of($type, \\BackedEnum::class);\nif (!in_array($type, $allowed, true) && !$isEnumType && !is_callable($type)) {\n    throw new \\InvalidArgumentException(\"Unsupported typecast type '{$type}'\");\n}","typeGuard":"function isValidTypecastType($type): bool\n{\n    return is_callable($type)\n        || in_array($type, ['integer', 'float', 'boolean', 'string'], true)\n        || (PHP_VERSION_ID >= 80100 && is_string($type) && is_subclass_of($type, \\BackedEnum::class));\n}","tryCatchPattern":null,"preventionTips":["Use the TYPE_* constants instead of hand-written strings in attributeTypes","Use callables for custom conversions and backed enums for enum casting on PHP 8.1+","Add a config smoke test that iterates attributeTypes and rejects unknown type names at boot"],"tags":["php","yii2","behavior","typecast","enums","configuration"],"backgroundTag":"unsupported-type-value","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}