{"record":{"id":"14fbe133a12ab7f6","repo":"phalcon/cphalcon","slug":"value-at-index-key-type-type-cannot-be-r","errorCode":null,"errorMessage":"Value at index: \"{key}\" type: \"{type}\" cannot be rendered","messagePattern":"Value at index: \"(.+?)\" type: \"(.+?)\" cannot be rendered","errorType":"exception","errorClass":"Phalcon\\Html\\Exceptions\\AttributeNotRenderable","httpStatus":null,"severity":"error","filePath":"phalcon/Html/Attributes.zep","lineNumber":85,"sourceCode":"        /**\n         * Just in case remove the \"escape\" attribute\n         */\n        unset results[\"escape\"];\n\n        /**\n         * Escape values through the configurable AttributeEscaper so a single\n         * implementation owns attribute escaping. ENT_QUOTES reproduces the\n         * previous hardcoded htmlspecialchars() call byte for byte - the\n         * \"utf-8\" encoding and double-encode defaults already match.\n         */\n        let escaper = new AttributeEscaper();\n        escaper->setFlags(ENT_QUOTES);\n\n        let result = \"\";\n        for key, value in results {\n            if typeof key === \"string\" && null !== value {\n                if (typeof value === \"array\" || is_resource(value)) {\n                    throw new AttributeNotRenderable(key, gettype(value));\n                }\n\n                let result .= key . \"=\\\"\"\n                . escaper->escape(value)\n                . \"\\\" \";\n            }\n        }\n\n        return result;\n    }\n}\n","sourceCodeStart":67,"sourceCodeEnd":97,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Html/Attributes.zep#L67-L97","documentation":"Phalcon\\Html\\Attributes::render() serializes every attribute as key=\"value\" through an HTML escaper that only accepts scalars. When a value is an array or a resource, no unambiguous string representation exists, so it throws AttributeNotRenderable with the key and its gettype().","triggerScenarios":"echo $attributes after $attributes->set('class', ['btn', 'btn-primary']); passing a stream/resource (for example an uploaded-file handle) as an attribute value; merging nested arrays from user input into an Attributes instance.","commonSituations":"Setting data-* attributes from decoded JSON that contains nested objects; building element attributes from unvalidated request arrays; assigning a file handle as a pseudo-attribute.","solutions":["Flatten arrays to a string before setting: ->set('class', implode(' ', ['btn', 'btn-primary']))","Serialize structured values explicitly: ->set('data-config', json_encode($config))","Filter the attributes so only scalar (string|int|float|bool) values remain before render()"],"exampleFix":"// before\n$attributes->set('class', ['btn', 'btn-primary']);\necho $attributes->render(); // AttributeNotRenderable\n\n// after\n$attributes->set('class', implode(' ', ['btn', 'btn-primary']));\necho $attributes->render();","handlingStrategy":"type-guard","validationCode":"$renderable = [];\nforeach ($attributes as $key => $value) {\n    if (is_array($value)) {\n        $value = implode(' ', $value);\n    }\n\n    if (is_scalar($value) || $value === null) {\n        $renderable[$key] = $value;\n    }\n}\n\n$attrs = new \\Phalcon\\Html\\Attributes($renderable);","typeGuard":"/** @param mixed $value */\nfunction isRenderableAttributeValue($value): bool\n{\n    return $value === null || is_scalar($value);\n}","tryCatchPattern":"try {\n    echo $attributes->render();\n} catch (\\Phalcon\\Html\\Exceptions\\AttributeNotRenderable $e) {\n    // message names the offending key and its type; drop or serialize it, then retry\n    error_log($e->getMessage());\n}","preventionTips":["Flatten array values (implode) or json_encode() them at the point where attributes are set","Never merge unvalidated request arrays directly into Attributes","Filter attributes through an is_scalar() pass in shared render helpers"],"tags":["phalcon","html","attributes","render","invalid-value"],"backgroundTag":"invalid-attribute-value","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}