{"record":{"id":"c7fb27c659789ead","repo":"phalcon/cphalcon","slug":"only-scalar-values-can-be-assigned-to-ui-component","errorCode":null,"errorMessage":"Only scalar values can be assigned to UI components","messagePattern":"Only scalar values can be assigned to UI components","errorType":"exception","errorClass":"Phalcon\\Tag\\Exception","httpStatus":null,"severity":"error","filePath":"phalcon/Tag.zep","lineNumber":1122,"sourceCode":"        return Select::selectField(parameters, data);\n    }\n\n    /**\n     * Set autoescape mode in generated HTML\n     */\n    public static function setAutoescape(bool autoescape) -> void\n    {\n        let self::autoEscape = autoescape;\n    }\n\n    /**\n     * Assigns default values to generated tags by helpers\n     */\n    public static function setDefault( string id, value) -> void\n    {\n        if value !== null {\n            if unlikely (typeof value == \"array\" || typeof value == \"object\") {\n                throw new Exception(\n                    \"Only scalar values can be assigned to UI components\"\n                );\n            }\n        }\n\n        let self::displayValues[id] = value;\n    }\n\n    /**\n     * Assigns default values to generated tags by helpers\n     *\n     * @phpstan-param tag_display_values $values\n     */\n    public static function setDefaults( array values, bool merge = false) -> void\n    {\n        if merge && typeof self::displayValues == \"array\" {\n            let self::displayValues = array_merge(self::displayValues, values);\n        } else {","sourceCodeStart":1104,"sourceCodeEnd":1140,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Tag.zep#L1104-L1140","documentation":"Phalcon\\Tag::setDefault() seeds default values that tag helpers use to pre-fill form fields. Because every default is later echoed into HTML markup, only scalars are usable; an array or object value throws Phalcon\\Tag\\Exception ('Only scalar values can be assigned to UI components'). null is explicitly allowed and is the supported way to clear a default.","triggerScenarios":"Tag::setDefault('category', ['fruits', 'vegetables']); Tag::setDefault('user', $user) — assigning an object/Resultset instead of a field; arrays leaking in from request->getPost() when a field was submitted multiple times.","commonSituations":"Pre-filling a select's default with its options array instead of the selected key; assigning model objects rather than model properties; defaults sourced from decoded JSON whose values are nested arrays.","solutions":["Assign the scalar field: Tag::setDefault('name', $user->name)","For objects that must appear, format them to string first — cast or call a __toString()-bearing method","If the value is a list, it belongs in the helper's options (e.g. select options), not in setDefault"],"exampleFix":"// before\n\\Phalcon\\Tag::setDefault('category', $categories); // array -> throws\n\n// after\n\\Phalcon\\Tag::setDefault('category', (int) $request->get('category', 'int', 0));","handlingStrategy":"validation","validationCode":"if (is_object($value) && method_exists($value, '__toString')) {\n    $value = (string) $value;\n}\n\nif (null === $value || is_scalar($value)) {\n    \\Phalcon\\Tag::setDefault('name', $value);\n}","typeGuard":"function isScalarTagDefault($value): bool\n{\n    return null === $value || is_scalar($value);\n}","tryCatchPattern":null,"preventionTips":["Store only string/int/float/bool defaults — typically filtered request input","Assign model fields ($user->name), never model objects, as defaults","Clear defaults deliberately with null (supported), never by assigning arrays or objects"],"tags":["phalcon","tag","forms","scalar-validation"],"backgroundTag":"invalid-attribute-value-type","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}