Deprecate TypedExpression in favor of ExpressionWithReturnType - #12543
Merged
Conversation
GromNaN
force-pushed
the
feature/typed-expression-name
branch
from
July 31, 2026 20:20
8a25471 to
6a33845
Compare
`TypedExpression::getReturnType()` returns a `Doctrine\DBAL\Types\Type` instance, which forces implementers to perform a static, global type lookup (`Type::getType()`). `SqlWalker` then converts the instance back to a name via `TypeRegistry::lookupName()`, making the round-trip pointless and introducing two static `Type::*` calls that block moving the ORM to instance-based type registries. Introduce `Doctrine\ORM\Query\AST\ExpressionWithReturnType`, which exposes the DBAL type name directly (`getReturnTypeName(): string`). `SqlWalker` prefers the new interface, falls back to the legacy one with a deprecation notice, and finally to the `'string'` default. `CountFunction` and `LengthFunction` now implement both interfaces: `getReturnTypeName()` returns a plain `Types::*` constant, and the legacy `getReturnType()` delegates and is marked `@deprecated`.
GromNaN
force-pushed
the
feature/typed-expression-name
branch
from
July 31, 2026 20:29
6a33845 to
a03ae56
Compare
SenseException
approved these changes
Aug 3, 2026
greg0ire
approved these changes
Aug 4, 2026
Member
|
Thanks @GromNaN ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improvement
Follow-up to this comment.
Type::*calls with instance-basedTypeRegistrylookups #12421History
The
TypedExpressioninterface was introduced in December 2019 (commit 24e9a7c, issue #7941) to let DQL functions declare their scalar return type. At the time, DBAL 2.x exposedType::getName()on the instance, soSqlWalkercheaply extracted the name via\$expr->getReturnType()->getName(). Returning aTypeobject was the natural handle for "a type" and required no static lookup on the walker side.DBAL 4 removed
Type::getName()in favour ofTypeRegistry::lookupName($type).SqlWalkerhad to reach forType::getTypeRegistry()->lookupName(...), and implementers had to keep calling the staticType::getType(Types::INTEGER)to hand back aTypeinstance the walker only uses to extract a name. The round-trip is vestigial, and it pins two staticType::*calls that block the instance-based type registry work in #12421.Solution
Introduce a new interface
Doctrine\ORM\Query\AST\ExpressionWithReturnTypethat exposes the DBAL type name directly.TypedExpressionis deprecated;SqlWalkerprefers the new interface, falls back to the legacy one with a runtime deprecation, and finally to the historical'string'default.Upgrade
Before:
After: