-
-
Notifications
You must be signed in to change notification settings - Fork 151
Fix type inference for container->get() with string service IDs #2956
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
base: master
Are you sure you want to change the base?
Fix type inference for container->get() with string service IDs #2956
Conversation
- Use TypeFactory::class() instead of fromString() for proper instance types - Return null instead of object|null when service is not found - Allow custom type resolvers to fully override inferred types This improves type inference accuracy for Symfony DI container get() method by ensuring services return proper reflected class types instead of generic class-string types.
| if (empty($id) || empty($class)) { | ||
| return null; | ||
| } | ||
| // Use TypeFactory::class() to create an instance type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant comment ...
|
This looks ok... but it's not clear to me what the problem was? in what way(s) is this an improvement? what concrete benefits are there? |
|
ill make a cleaner pr |
|
hm, indeed I see! the only potential issue is erasing the original type information ( it would be nice if the tests were updated to account for the bad behavior, but perhaps it's not that easy |


This improves type inference accuracy for Symfony DI container get() method by ensuring services return proper reflected class types instead of generic class-string types.