phalcon/cphalcon · error · Phalcon\Forms\Exceptions\SchemaEntryMissingKey
Form schema definition at index {index} is missing required
Error message
Form schema definition at index {index} is missing required key "type" What it means
ArrayLoader::validateDefinition() requires every definition array to carry a non-empty 'type' key, since the type selects the element factory used to instantiate the element. A definition missing 'type', or with an empty/falsy type value, throws SchemaEntryMissingKey reporting both the index and the key name 'type'.
Source
Thrown at phalcon/Forms/Loader/ArrayLoader.zep:64
}
return this->definitions;
}
/**
* @param mixed $definition
* @param int $index
*
* @throws Exception
*/
protected function validateDefinition(var definition, int index) -> void
{
if typeof definition !== "array" {
throw new SchemaEntryNotArray(index);
}
if !isset definition["type"] || empty definition["type"] {
throw new SchemaEntryMissingKey(index, "type");
}
if !isset definition["name"] || empty definition["name"] {
throw new SchemaEntryMissingKey(index, "name");
}
}
}
View on GitHub (pinned to b7419de9cd)
Solutions
- Add a non-empty 'type' key to the definition at the reported index, e.g. ['type' => 'text', 'name' => 'email']
- If you generate definitions in code, assert isset($def['type']) && $def['type'] !== '' before passing them to the loader
- Re-check the reported index in the exception message — it points at the exact entry
Example fix
// before [ ['name' => 'email'] ] // after [ ['type' => 'email', 'name' => 'email'] ]
Defensive patterns
Strategy: validation
Validate before calling
foreach ($definitions as $index => $definition) {
if (!isset($definition['type']) || $definition['type'] === '') {
throw new \InvalidArgumentException(
"Schema entry {$index} is missing a non-empty 'type'"
);
}
}
$defs = (new \Phalcon\Forms\Loader\ArrayLoader($definitions))->load(); Type guard
function hasValidType(array $definition): bool
{
return isset($definition['type'])
&& is_string($definition['type'])
&& $definition['type'] !== '';
} Try / catch
try {
$defs = (new \Phalcon\Forms\Loader\ArrayLoader($definitions))->load();
} catch (\Phalcon\Forms\Exceptions\SchemaEntryMissingKey $e) {
// e->getMessage() names index and key ('type'); route it to the schema author
$logger->error($e->getMessage());
throw $e;
} Prevention
- Write a small schema unit test that loads every bundled form schema at CI time
- Prefer generating definitions from typed PHP arrays so missing keys fail statically
- Treat the 'type' key as required in any schema documentation and example files
When it happens
Trigger: A schema entry like ['name' => 'email'] with no 'type' key; an entry with 'type' => '' or 'type' => 0; renaming the key in a generator (e.g. 'element' instead of 'type') without updating the schema.
Common situations: Hand-edited schema files where the type line was deleted; code that builds definitions dynamically and omits the type branch for some fields; schema produced by another tool with different key names.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Form schema definition at index {index} is missing required
- Form schema definition at index {index} must be an array
- Unknown form element type "{type}"
- JSON form schema is invalid: {detail}
- JSON form schema must decode to an array
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/bf98ce84e26ee26b.
Report an issue: GitHub.