{"record":{"id":"d8fe9e3873c18c66","repo":"phalcon/cphalcon","slug":"form-schema-definition-at-index-index-must-be-an","errorCode":null,"errorMessage":"Form schema definition at index {index} must be an array","messagePattern":"Form schema definition at index (.+?) must be an array","errorType":"exception","errorClass":"Phalcon\\Forms\\Exceptions\\SchemaEntryNotArray","httpStatus":null,"severity":"error","filePath":"phalcon/Forms/Loader/ArrayLoader.zep","lineNumber":60,"sourceCode":"        var definition, index;\n\n        for index, definition in this->definitions {\n            this->validateDefinition(definition, (int) index);\n        }\n\n        return this->definitions;\n    }\n\n    /**\n     * @param mixed $definition\n     * @param int   $index\n     *\n     * @throws Exception\n     */\n    protected function validateDefinition(var definition, int index) -> void\n    {\n        if typeof definition !== \"array\" {\n            throw new SchemaEntryNotArray(index);\n        }\n\n        if !isset definition[\"type\"] || empty definition[\"type\"] {\n            throw new SchemaEntryMissingKey(index, \"type\");\n        }\n\n        if !isset definition[\"name\"] || empty definition[\"name\"] {\n            throw new SchemaEntryMissingKey(index, \"name\");\n        }\n    }\n}\n","sourceCodeStart":42,"sourceCodeEnd":72,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Forms/Loader/ArrayLoader.zep#L42-L72","documentation":"Phalcon\\Forms\\Loader\\ArrayLoader validates every schema entry via validateDefinition(); the first check requires the definition at each index to be a PHP array. Anything else at that index — a string, int, null, or stdClass — throws SchemaEntryNotArray with the failing index, because element definitions must be key/value maps.","triggerScenarios":"new ArrayLoader($definitions)->load() where $definitions[3] is a scalar or stdClass; JSON decoded without assoc=true producing stdClass rows; YAML entries that parse to plain strings.","commonSituations":"Hand-written schema arrays with a stray quoted entry; feeding mixed data from an API; a custom loader that skips the assoc flag when decoding.","solutions":["Ensure every entry of the definitions list is itself an array (starts with '[' / '- ' in YAML)","Decode JSON with assoc=true so nested documents become arrays, not stdClass","Map objects to arrays before constructing the loader: $definitions = array_map(fn($d) => (array) $d, $definitions)"],"exampleFix":"// before\n$loader = new ArrayLoader([\n    ['type' => 'text', 'name' => 'email'],\n    'submit', // string, not an array\n]);\n\n// after\n$loader = new ArrayLoader([\n    ['type' => 'text', 'name' => 'email'],\n    ['type' => 'submit', 'name' => 'send'],\n]);","handlingStrategy":"validation","validationCode":"$invalid = [];\nforeach ($definitions as $index => $definition) {\n    if (!is_array($definition)) {\n        $invalid[] = $index;\n    }\n}\n\nif ($invalid !== []) {\n    throw new \\InvalidArgumentException(\n        'Schema entries must be arrays; bad indexes: ' . implode(', ', $invalid)\n    );\n}\n\n$formDefs = (new \\Phalcon\\Forms\\Loader\\ArrayLoader($definitions))->load();","typeGuard":"/** @param mixed $definition */\nfunction isSchemaEntry($definition): bool\n{\n    return is_array($definition);\n}","tryCatchPattern":"try {\n    $defs = (new \\Phalcon\\Forms\\Loader\\ArrayLoader($definitions))->load();\n} catch (\\Phalcon\\Forms\\Exceptions\\SchemaEntryNotArray $e) {\n    // the message names the offending index; surface it to the config author\n    throw new \\RuntimeException('Bad form schema: ' . $e->getMessage(), 0, $e);\n}","preventionTips":["Always decode external JSON with assoc=true before building schema arrays","Author schema files in a linted format (JSON Schema validator or YAML linter) in CI","When generating definitions in code, type the generator to return array<int, array<string, mixed>>"],"tags":["phalcon","forms","schema","loader","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}