-
Notifications
You must be signed in to change notification settings - Fork 2.5k
use the empty string instead of null as an array offset #12160
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: 3.5.x
Are you sure you want to change the base?
Conversation
0e2692f
to
3aa7791
Compare
What prompted you to contribute this? Was it static analysis or was it tests? If it's static analysis and there are no unit tests covering theses cases, maybe we should use assertions instead? |
Sorry I forgot to mention. This is a deprecation that will be introduced with PHP 8.5. We caught this in the Symfony CI. So I enabled a PHP 8.5 job on my fork and these were the places that were caught by the tests. |
Oh ok so there are actual situations where this can happen 🤯 |
{ | ||
if (isset($this->class->fieldMappings[$this->class->versionField]->inherited)) { | ||
$definingClassName = $this->class->fieldMappings[$this->class->versionField]->inherited; | ||
if (isset($this->class->fieldMappings[$this->class->versionField ?? '']->inherited)) { |
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.
If we take this one as an example, does it happen in a realistic scenario, or would it make sense to trigger a deprecation ourselves in the next major release?
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.
I have no idea. 🤷 But it's actually triggered a lot of times in the tests (see https://github.com/xabbuh/orm/actions/runs/17612071318/job/50036129395#step:6:84).
src/Query/SqlWalker.php
Outdated
$sqlParts[] = $col . ' AS ' . $columnAlias; | ||
|
||
$this->scalarResultAliasMap[$resultAlias][] = $columnAlias; | ||
$this->scalarResultAliasMap[$resultAlias ?? ''][] = $columnAlias; |
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.
should it even be added in scalarResultAliasMap
if there is no result alias ?
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.
I am not sure here about the implications if we don't add it. In other places we use the $scalarResultCounter
property but I have no idea if that would work as expected here.
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.
after re-reading how the map is accessed in walkResultVariable()
it's probably safe to assume that adding an entry here in case of $resultAlias
being null
doesn't make much sense
// Get any aliases that are available for select expressions. | ||
foreach ($AST->selectClause->selectExpressions as $selectExpression) { | ||
$selectAliasToExpressionMap[$selectExpression->fieldIdentificationVariable] = $selectExpression->expression; | ||
$selectAliasToExpressionMap[$selectExpression->fieldIdentificationVariable ?? ''] = $selectExpression->expression; |
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.
shouldn't we rather skip expressions that have no identification variable (instead of keeping only the last one as they will anyway override each other in that map) ?
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.
That's true, it didn't make a difference before as we never read from the map below when $orderByItem->expression
was not a string. So we can just abstain from adding it.
foreach ($orderByClause->orderByItems as $orderByItem) { | ||
if (is_string($orderByItem->expression) && isset($selectAliasToExpressionMap[$orderByItem->expression])) { | ||
$orderByItem->expression = $selectAliasToExpressionMap[$orderByItem->expression]; | ||
if (is_string($orderByItem->expression) && isset($selectAliasToExpressionMap[$orderByItem->expression ?? ''])) { |
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.
this is useless, as is_string($orderByItem->expression)
already ensures it is not null (same on next line)
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.
indeed, reverted
{ | ||
if (isset($this->class->fieldMappings[$this->class->versionField]->inherited)) { | ||
$definingClassName = $this->class->fieldMappings[$this->class->versionField]->inherited; | ||
if (isset($this->class->fieldMappings[$this->class->versionField ?? '']->inherited)) { |
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.
I think it will be clearer to handle the (common) case of classes without a version field explicitly instead of attempting an array check with the empty string.
if (isset($this->class->fieldMappings[$this->class->versionField ?? '']->inherited)) { | |
if ($this->class->versionField !== null && isset($this->class->fieldMappings[$this->class->versionField]->inherited)) { |
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.
done
This PR was merged into the 6.4 branch. Discussion ---------- Fix ord()-related PHP 8.5 deprecations | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT The remaining deprecations will be fixed by doctrine/orm#12160 Commits ------- 5314fd5 Fix ord()-related PHP 8.5 deprecations
530099d
to
3bb9931
Compare
thanks for the reviews, comments addressed, this is ready from my side |
I thought it might be great if PHPStan could help us in that regard. phpstan/phpstan#13592 |
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.
LGTM, just a nit-pick.
src/Query/SqlWalker.php
Outdated
$sqlParts[] = $col . ' AS ' . $columnAlias; | ||
|
||
$this->scalarResultAliasMap[$resultAlias][] = $columnAlias; | ||
if (is_string($resultAlias)) { |
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.
Let's make it explicit that this is actually a null-check.
if (is_string($resultAlias)) { | |
if ($resultAlias !== null) { |
src/Query/SqlWalker.php
Outdated
$sqlParts[] = $col . ' AS ' . $columnAlias; | ||
|
||
$this->scalarResultAliasMap[$resultAlias][] = $columnAlias; | ||
if (is_string($resultAlias)) { |
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.
Same.
cb1637c
No description provided.