doctrine/orm · error · Exception
Unknown property {key} on class {class}
Error message
Unknown property {key} on class {class} What it means
Doctrine ORM builds its DiscriminatorColumnMapping value object from a plain mapping array via DiscriminatorColumnMapping::fromMappingArray(), which is what the XML/YAML/PHP mapping drivers and cached metadata feed. After the required 'type', 'fieldName' and 'name' keys are consumed, every remaining key is assigned onto the mapping object using property_exists(); a key that matches no public property of DiscriminatorColumnMapping throws this exception, naming the offending key and class.
Source
Thrown at src/Mapping/DiscriminatorColumnMapping.php:63
* options?: array<string, mixed>|null,
* } $mappingArray
*/
public static function fromMappingArray(array $mappingArray): self
{
$mapping = new self(
$mappingArray['type'],
$mappingArray['fieldName'],
$mappingArray['name'],
);
foreach ($mappingArray as $key => $value) {
if (in_array($key, ['type', 'fieldName', 'name'])) {
continue;
}
if (property_exists($mapping, $key)) {
$mapping->$key = $value ?? $mapping->$key;
} else {
throw new Exception('Unknown property ' . $key . ' on class ' . static::class);
}
}
return $mapping;
}
/** @return list<string> */
public function __sleep(): array
{
$serialized = ['type', 'fieldName', 'name'];
foreach (['length', 'columnDefinition', 'enumType', 'options'] as $stringOrArrayKey) {
if ($this->$stringOrArrayKey !== null) {
$serialized[] = $stringOrArrayKey;
}
}
return $serialized;View on GitHub (pinned to d9b9ff7301)
Solutions
- Fix or remove the offending key: only type, fieldName, name, length, columnDefinition, enumType and options are accepted on discriminator-column mappings.
- If the key belongs to a regular field (precision, scale, ...), move it to the <field>/<column> mapping, not the discriminator column.
- Clear cached metadata (doctrine orm:clear-cache:metadata) so a stale mapping array from an older ORM version is regenerated.
Example fix
// before
DiscriminatorColumnMapping::fromMappingArray([
'type' => 'string',
'fieldName' => 'dtype',
'name' => 'discr',
'lenght' => 255, // typo: unknown property
]);
// after
DiscriminatorColumnMapping::fromMappingArray([
'type' => 'string',
'fieldName' => 'dtype',
'name' => 'discr',
'length' => 255,
]); Defensive patterns
Strategy: validation
Validate before calling
$allowed = ['type', 'fieldName', 'name', 'length', 'columnDefinition', 'enumType', 'options'];
$unknown = array_diff(array_keys($mappingArray), $allowed);
if ($unknown !== []) {
throw new InvalidArgumentException('Unsupported discriminator-column keys: ' . implode(', ', $unknown));
}
return DiscriminatorColumnMapping::fromMappingArray($mappingArray); Try / catch
try { DiscriminatorColumnMapping::fromMappingArray($array); } catch (Exception $e) { throw new MappingConfigurationException('Invalid <discriminator-column> mapping: ' . $e->getMessage(), 0, $e); } Prevention
- Keep mapping arrays in one place so key typos surface immediately.
- Run metadata loading in CI (instantiate the EntityManager / warm the cache) to catch bad mappings before deploy.
- Regenerate cached metadata after ORM upgrades.
When it happens
Trigger: Calling DiscriminatorColumnMapping::fromMappingArray() (directly or via a mapping driver / metadata factory) with an array containing a key other than type, fieldName, name, length, columnDefinition, enumType, options. Typical offenders: a misspelled key like 'lenght', or a key valid on regular column mappings (precision, scale, unique, nullable) that DiscriminatorColumnMapping does not define.
Common situations: Hand-written XML or YAML <discriminator-column> definitions with misspelled/unsupported attributes; PHP array mappings copied from a #[Column] definition; metadata cached by an older ORM version with different key names; custom mapping drivers that pass extra keys through.
Related errors
- Unrecognized access strategy type [%s]
- If you want to use a "READ_WRITE" cache an implementation of
- Lazy loading proxies require PHP 8.4 or higher.
- The lazy ghost object feature cannot be disabled anymore. Pl
- Rejecting ID collisions in the identity map cannot be disabl
AI-assisted analysis of doctrine/orm@d9b9ff7301 (2026-08-21).
Data as JSON: /api/errors/ffac3497734e2ab2.
Report an issue: GitHub.