doctrine/orm · error · OutOfBoundsException
Unknown field: {name} ::${field}
Error message
Unknown field: {name} ::${field} What it means
LegacyReflectionFields is an ArrayAccess wrapper around a ClassMetadata's map of ReflectionProperty objects, keyed by field names, association names and embedded sub-paths like 'parent.child'. offsetGet() throws OutOfBoundsException when the requested name is not in that map, i.e. it is not a mapped field of that class.
Source
Thrown at src/Mapping/LegacyReflectionFields.php:116
} else {
$parentClass = $this->classMetadata->fieldMappings[$parentField]->originalClass;
}
/** @psalm-var class-string $parentClass */
/** @psalm-var class-string $originalClass */
$this->reflFields[$field] = new ReflectionEmbeddedProperty(
$this->getAccessibleProperty($parentClass, $parentField),
$this->reflFields[$field],
$originalClass,
);
}
}
return $this->reflFields[$field];
}
throw new OutOfBoundsException('Unknown field: ' . $this->classMetadata->name . ' ::$' . $field);
}
/**
* @param string $offset
* @param ReflectionProperty $value
*/
public function offsetSet($offset, $value): void // phpcs:ignore
{
$this->reflFields[$offset] = $value;
}
/** @param string $offset */
public function offsetUnset($offset): void // phpcs:ignore
{
unset($this->reflFields[$offset]);
}
/** @psalm-param class-string $class */View on GitHub (pinned to d9b9ff7301)
Solutions
- Use the public API: $metadata->getReflectionProperty($field) / $metadata->getAssociationMapping(...) instead of raw array access.
- Guard lookups with in_array($field, $metadata->getFieldNames(), true) or array_key_exists($field, $metadata->reflFields) first.
- For embedded sub-fields, use the dotted path ('address.city') that the map is keyed by.
Example fix
// before
$prop = $metadata->reflFields['emial']; // typo -> OutOfBoundsException
// after
$field = 'email';
$prop = array_key_exists($field, $metadata->reflFields)
? $metadata->reflFields[$field]
: throw new RuntimeException("Unknown field {$field} on {$metadata->name}"); Defensive patterns
Strategy: validation
Validate before calling
$field = 'email';
if (! array_key_exists($field, $metadata->reflFields)
&& ! $metadata->hasField($field) && ! $metadata->hasAssociation($field)
) {
throw new OutOfBoundsException("Unknown field '{$field}' on {$metadata->name}");
} Prevention
- Prefer $metadata->getReflectionProperty($field) over raw reflFields array access.
- Derive field names from the metadata (fieldNames/associationNames), not string literals.
- Add tests for custom hydrators/listeners so renamed fields fail fast.
When it happens
Trigger: Reading $classMetadata->reflFields['someName'] (or LegacyReflectionFields offsetGet) where 'someName' is not a mapped field/association/embedded path of the class — typos, a field removed from the mapping, or querying the metadata of the wrong entity class.
Common situations: Custom hydrators, entity listeners or fixtures that reach into ClassMetadata::reflFields directly; accessing an association's target field on the source class metadata; code that keeps working by accident until a property is renamed.
Related errors
- Given property is not readonly.
- No metadata for DQL alias: %s
- Uninitialized result set mapping.
- Unable to use access strategy type of [%s] without a Concurr
- Unrecognized access strategy type [%s]
AI-assisted analysis of doctrine/orm@d9b9ff7301 (2026-08-21).
Data as JSON: /api/errors/5018106d0eb75297.
Report an issue: GitHub.