doctrine / doctrine/DoctrineBundle

[ORM 3.0] BC Break in UnderscoreNamingStrategy constructor breaks container compilation

Open
#2,196 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
4.8k
Forks
482
Avg merge
1h 51m
Merged PRs (30d)
3

Description

## Bug Report

| Q | A
|-------------------------------------------- | ------
| Bundle Version | 2.12.x / 2.13.x
| Symfony Version | 6.4.x / 7.x
| PHP Version | 8.1+
| Doctrine ORM Version | 3.x

### Summary

When upgrading to Doctrine ORM 3.x, the service definition for `doctrine.orm.naming_strategy.underscore` in `DoctrineBundle` remains configured with two arguments. However, the `UnderscoreNamingStrategy` constructor in ORM 3.0 has dropped the second parameter, leading to a container compilation error.

Crucially, as DoctrineBundle 3.x appears to be moving toward dropping 8.3 support, users on PHP 8.3 are reliant on the 2.x branch of this bundle to remain compatible with Doctrine ORM 3.x.

### Current behaviour
The service is defined in `config/orm.php` with a hardcoded set of two arguments:

```php
// config/orm.php
$container->setDefinition('doctrine.orm.naming_strategy.underscore', new Definition(UnderscoreNamingStrategy::class))
->setArguments([CASE_LOWER, true])
->setPublic(false);
```

When using Doctrine ORM 3.x, this results in the following error during container validation or compilation:
> [ERROR] Service "doctrine.orm.naming_strategy.underscore" only accepts 1 parameters, 2 provided.

This occurs because the $numberAware parameter was removed in ORM 3.0 (the strategy is now number-aware by default).

### Expected behaviour
The service definition should be updated to detect the version of Doctrine ORM being used. If ORM 3.x is present, only one argument (CASE_LOWER) should be passed.

The service definition in config/orm.php should be conditional based on the installed version of Doctrine ORM.
For ORM 2.x: Keep [CASE_LOWER, true].
For ORM 3.x: Use [CASE_LOWER].

### Why this is blocking
Our project is currently on PHP 8.3. We cannot easily move to DoctrineBundle 3.x due to its PHP requirements, yet we are prevented from upgrading to upgrading to Doctrine ORM 3.x, because the 2.13.x branch of DoctrineBundle contains this incompatible service definition. This leaves users on PHP 8.3 or lower without a viable path to ORM 3.x.

### Extra information
This BC break is documented in the Doctrine ORM 3.0 upgrade guide: https://github.com/doctrine/orm/blob/3.6.x/UPGRADE.md#bc-break-underscorenamingstrategy-is-number-aware-only

(also

Contributor guide

Open the contributing guide

Research direction

Start in config/orm.php and compare its two constructor arguments with the Doctrine ORM 3.0 upgrade guide entry for UnderscoreNamingStrategy. Verify the installed ORM version before choosing the argument list. Done means Doctrine ORM 2.x retains [CASE_LOWER, true], while ORM 3.x compiles with [CASE_LOWER] without the container validation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.