Skip to content

fix(doctrine): avoid deprecated ArrayAccess on FieldMapping in DoctrineORMListener#506

Open
HecFranco wants to merge 1 commit into
lexik:masterfrom
HecFranco:fix/doctrine-field-mapping-arrayaccess
Open

fix(doctrine): avoid deprecated ArrayAccess on FieldMapping in DoctrineORMListener#506
HecFranco wants to merge 1 commit into
lexik:masterfrom
HecFranco:fix/doctrine-field-mapping-arrayaccess

Conversation

@HecFranco
Copy link
Copy Markdown
Contributor

@HecFranco HecFranco commented May 5, 2026

Fix Doctrine ORM 3 FieldMapping ArrayAccess deprecation

This PR fixes a Doctrine ORM 3.x deprecation triggered when accessing FieldMapping metadata using array syntax.

Doctrine ORM deprecated ArrayAccess on Doctrine\ORM\Mapping\FieldMapping in doctrine/orm#11211, and this behavior is expected to be removed in ORM 4.0.

As a result, code like this:

$fieldMapping['type']

can trigger the following deprecation notice:

Relying on ArrayAccess for accessing mapping information on a FieldMapping instance is deprecated and will not be possible in Doctrine ORM 4.0. Use the public properties instead.

Context

The deprecation is currently triggered in DoctrineORMListener::loadClassMetadata, where the bundle checks the mapped field type before adjusting the length of string fields for MySQL connections using the utf8mb4 charset.

The existing behavior is preserved:

  • only Lexik translation entities are affected;
  • only fields mapped as string are considered;
  • the length is still adjusted to 191 when the connection charset is utf8mb4.

What changed

This PR replaces direct array access to the Doctrine field mapping with a small helper method that resolves the field type safely from either:

  • a Doctrine\ORM\Mapping\FieldMapping object, using its public type property;
  • or an array-based mapping, using the existing type key.

This keeps the code compatible with Doctrine ORM 3.x while remaining tolerant of array-based metadata mappings.

Why

This removes the Doctrine ORM 3.x deprecation notice and prepares this part of the bundle for Doctrine ORM 4 compatibility, without changing the existing behavior of the metadata adjustment logic.

Tests

Not run locally. The change is limited to metadata mapping access and preserves the existing logic.

Fixes #491.

- Updated field mapping logic to support both legacy array mapping and the new FieldMapping object introduced in Doctrine ORM 3.x.
- Ensured backward compatibility with existing implementations while preparing for future ORM 4.0 changes.
@HecFranco
Copy link
Copy Markdown
Contributor Author

Thanks for maintaining LexikTranslationBundle — it would be great if one of the maintainers could review this PR when you have a moment. Happy to adjust anything based on your feedback.

@HecFranco
Copy link
Copy Markdown
Contributor Author

Hi maintainers,

Just following up on this PR. It addresses the Doctrine ORM 3.x deprecation caused by using ArrayAccess on FieldMapping, which is expected to stop working in Doctrine ORM 4.0.

The change keeps the existing behavior intact while making the metadata access compatible with the newer Doctrine mapping API, and it also closes #491.

Would it be possible to review or merge this when you have a chance?

Happy to make any adjustments if needed.

Thanks again for maintaining this bundle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Doctrine ORM 4.0 deprecation: Replace ArrayAccess with direct property access on FieldMapping

1 participant