Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Foo:Bar entity short syntax #8818

Closed
beberlei opened this issue Jul 4, 2021 · 2 comments · Fixed by #8820
Closed

Deprecate Foo:Bar entity short syntax #8818

beberlei opened this issue Jul 4, 2021 · 2 comments · Fixed by #8820
Assignees
Milestone

Comments

@beberlei
Copy link
Member

beberlei commented Jul 4, 2021

We want to deprecate and remove the short alias naming of entities in manager, repository and DQL. This feature is available through the following configuration:

$configuration->addEntityNamespace('MyBundle', 'App\Entity');
$entityManager->find('MyBundle:User', $id);
$entityManager->createQuery('SELECT u FROM MyBundle:User');

Using short alias naming prevents Psalm/PHPStan static analysis from working and also generally is confusing for people to see that are only used to the fully qualified class name syntax.

The short alias syntax was invented when PHP did not have the magic class constant yet, so we recommend all users to change their code using short aliases to use them:

-  $entityManager->find('MyBundle:User', $id);
+  $entityManager->find(User::class, $id);
-  $entityManager->createQuery('SELECT u FROM MyBundle:User');
+  $entityManager->createQuery('SELECT u FROM ' . User::class');

This deprecation should be triggered only on using the aliases, not on configuring them. This way it does not get triggered if the alias is just defined but never used.

@beberlei beberlei added this to the 2.10.0 milestone Jul 4, 2021
@beberlei beberlei self-assigned this Jul 4, 2021
beberlei added a commit to beberlei/doctrine2 that referenced this issue Jul 4, 2021
beberlei added a commit to beberlei/doctrine2 that referenced this issue Aug 4, 2021
greg0ire added a commit that referenced this issue Aug 5, 2021
…precation

[GH-8818] Deprecate entity namespace short aliases.
M0rgan01 pushed a commit to M0rgan01/PrestaShop that referenced this issue Jul 31, 2023
@Herz3h
Copy link

Herz3h commented Aug 11, 2023

I have been using getRepository($bundleName:$entityName); what is the alternative now that this is not working anymore ?

Error says: Solution: See the doctrine/deprecations logs for new alternative approaches. but can't seem to find where that solution is.

@derrabus
Copy link
Member

Use the FQCN of the entity class.

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

Successfully merging a pull request may close this issue.

3 participants