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

  1. Use the public API: $metadata->getReflectionProperty($field) / $metadata->getAssociationMapping(...) instead of raw array access.
  2. Guard lookups with in_array($field, $metadata->getFieldNames(), true) or array_key_exists($field, $metadata->reflFields) first.
  3. 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

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


AI-assisted analysis of doctrine/orm@d9b9ff7301 (2026-08-21). Data as JSON: /api/errors/5018106d0eb75297. Report an issue: GitHub.