{"record":{"id":"cc80d7f4da64a66e","repo":"phalcon/cphalcon","slug":"translation-data-must-be-an-array","errorCode":null,"errorMessage":"Translation data must be an array","messagePattern":"Translation data must be an array","errorType":"exception","errorClass":"Phalcon\\Translate\\Exceptions\\InvalidDataType","httpStatus":null,"severity":"error","filePath":"phalcon/Translate/Adapter/NativeArray.zep","lineNumber":54,"sourceCode":"     * @phpstan-param translate_array_options $options\n     *\n     * @throws InvalidDataType\n     * @throws MissingContent\n     */\n    public function __construct(\n        <InterpolatorFactory> interpolator,\n        array options\n    ) {\n        var data;\n\n        parent::__construct(interpolator, options);\n\n        if unlikely !fetch data, options[\"content\"] {\n            throw new MissingContent();\n        }\n\n        if unlikely typeof data !== \"array\" {\n            throw new InvalidDataType();\n        }\n\n        let this->translate = data;\n    }\n\n    /**\n     * Check whether is defined a translation key in the internal array\n     *\n     * @deprecated\n     */\n    public function exists(string index) -> bool\n    {\n        return this->has(index);\n    }\n\n    /**\n     * Check whether is defined a translation key in the internal array\n     */","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Translate/Adapter/NativeArray.zep#L36-L72","documentation":"After confirming 'content' exists, NativeArray requires it to be an array; any other type throws Phalcon\\Translate\\Exceptions\\InvalidDataType (phalcon/Translate/Adapter/NativeArray.zep:54). The adapter stores the value directly in its translate map, so scalars, null, or objects cannot be used.","triggerScenarios":"new NativeArray($factory, ['content' => 'path/to/file.php']) — passing a file path like the Csv adapter instead of the array; content from json_decode($json) without the true flag (stdClass); include() returning int 1; a config value overwritten by a string.","commonSituations":"Mixing up adapter conventions (Csv takes a path, NativeArray takes the array); decoder flags lost in a refactor; env-specific config where one environment has a string instead of an array.","solutions":["Load the data first, then pass the array: ['content' => require $path] or the already-decoded array.","Use json_decode($json, true) so objects become arrays.","If what you have is a CSV file path, use the Csv adapter instead."],"exampleFix":"// before\n$t = new NativeArray($factory, ['content' => app_path('messages/en.php')]); // string path\n\n// after\n$t = new NativeArray($factory, ['content' => require app_path('messages/en.php')]);","handlingStrategy":"type-guard","validationCode":"if (!is_array($options['content'] ?? null)) {\n    throw new InvalidArgumentException('NativeArray content must be an array of translations');\n}","typeGuard":"/** @param mixed $content @return array<string,string> */\nfunction ensureTranslationArray(mixed $content): array\n{\n    return is_array($content) ? $content : [];\n}","tryCatchPattern":null,"preventionTips":["Use require for PHP dictionaries and json_decode(..., true) for JSON — never pass paths or stdClass.","Static-analyze factories with phpstan so content is known to be array<string,string>.","If you have a file path, choose the Csv adapter instead."],"tags":["phalcon","translate","native-array","type-mismatch","i18n"],"backgroundTag":"invalid-option-type","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}