Deprecation: Doctrine\ORM\Mapping\UnderscoreNamingStrategy without making it number aware is deprecated Deprecation: Doctrine\ORM\Mapping\UnderscoreNamingStrategy without making it number aware is deprecated symfony symfony

Deprecation: Doctrine\ORM\Mapping\UnderscoreNamingStrategy without making it number aware is deprecated


In most cases I would just answer this sort of question with a comment but I suspect other developers might run into this issue. I poked around a bit and could not find any explicit documentation on this issue. Perhaps because the DoctrineBundle is under the control of the Doctrine folks and not the Symfony developers. Or maybe I am just a bad searcher.

In any event, between 4.3 and 4.4 the service name for the underscore naming strategy was changed.

# doctrine.yamlorm:  # 4.3  naming_strategy: doctrine.orm.naming_strategy.underscore  # 4.4  naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware

And a deprecated message was added to warn developers to change the name. Would have been nice if the message was just a tiny bit more explicit but oh well.So if you are upgrading an existing app to 4.4 and beyond then you will probably need to manually edit your doctrine.yaml file to make the depreciation message go away.

Some more info (thanks @janh) on why the change was made:https://github.com/doctrine/orm/blob/2.8.x/UPGRADE.md#deprecated-number-unaware-doctrineormmappingunderscorenamingstrategyhttps://github.com/doctrine/orm/issues/7855

Still not really clear on why "they" chose to do things this way but oh well.You probably want to run "bin/console doctrine:schema:update --dump-sql" just to see if this impacts your database column names and adjust accordingly. The changes has been out for several weeks now and there does not seem to be many howls of outrage over the change so I guess most column names don't have embedded numbers. So far at least.


For those who works with symfony4.3 and still want this warning disapear you can add add new new service defintion in service.yaml

    custom_doctrine_orm_naming_strategy_underscore:    class: Doctrine\ORM\Mapping\UnderscoreNamingStrategy    arguments:        - 0        - true

and change the configuration of doctrine.yaml like this:

orm:    naming_strategy: custom_doctrine_orm_naming_strategy_underscore

before going straight forward committing this change I would suggest you to verify that passing true to the Doctrine\ORM\Mapping\UnderscoreNamingStrategy doesn't affect the expected behavior of your code.

// class UnderscoreNamingStrategy/** * Underscore naming strategy construct. * * @param int $case CASE_LOWER | CASE_UPPER */public function __construct($case = CASE_LOWER, bool $numberAware = false){    if (! $numberAware) {        @trigger_error(            'Creating ' . self::class . ' without making it number aware is deprecated and will be removed in Doctrine ORM 3.0.',            E_USER_DEPRECATED        );    }    $this->case    = $case;    $this->pattern = $numberAware ? self::NUMBER_AWARE_PATTERN : self::DEFAULT_PATTERN;}

Quick hint:

passing true to the c'tor will make the class use the NUMBER_AWARE_PATTERN instead of the DEFAULT_PATTERN

private const DEFAULT_PATTERN      = '/(?<=[a-z])([A-Z])/';private const NUMBER_AWARE_PATTERN = '/(?<=[a-z0-9])([A-Z])/';