Avoid using a null alias as an array offset in getAliases()#658
Avoid using a null alias as an array offset in getAliases()#658ardittirana wants to merge 1 commit into
Conversation
| // Only record an alias => table mapping when an alias exists. | ||
| // Using a null alias as an array offset is deprecated as of | ||
| // PHP 8.5, and such an entry is never read back below anyway. | ||
| if (! isset($expr->alias) || ($expr->alias === '')) { |
There was a problem hiding this comment.
It is better to check explicitly null
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #658 +/- ##
=========================================
Coverage 96.30% 96.30%
- Complexity 2254 2256 +2
=========================================
Files 90 90
Lines 4982 4984 +2
=========================================
+ Hits 4798 4800 +2
Misses 184 184
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
| } | ||
|
|
||
| // Only record an alias => table mapping when an alias exists. | ||
| // Using a null alias as an array offset is deprecated as of |
There was a problem hiding this comment.
The comment lines look like they where added by an AI
Please remove this line and below it adds no value
| [ | ||
| // An unaliased table alongside an aliased one. The unaliased | ||
| // table must not break alias resolution; previously its null | ||
| // alias was used as an array offset (deprecated in PHP 8.5). |
|
Thank you for this contribution! And finally please fix lint step |
Misc::getAliases() built a table-alias map with `$tables[$thisDb][$expr->alias] = $expr->table` for every FROM/JOIN expression. When a table has no alias, `$expr->alias` is null, so this used null as an array offset, which is deprecated as of PHP 8.5. The null-keyed entry was never read back: the only consumer looks up `$tables[$thisDb][$expr->table]`, whose offset is always a non-empty string. Skip expressions without an alias. getAliases() output is unchanged. Removes the now-resolved PossiblyNullArrayOffset baseline entry and adds a regression test.
04242cf to
1514837
Compare
|
Thanks for the review @williamdes, and for the helpful pointers. I've updated the PR:
Full suite is green locally. Please let me know if you'd like anything else adjusted. |
Resolves the
phpmyadmin/sql-parserside of phpmyadmin/phpmyadmin#20313.Problem
SelectStatement::getAliases()builds a table-alias map:for every
FROM/JOINexpression. When a table has no alias,$expr->aliasisnull, so this uses null as an array offset, which is deprecated as of PHP 8.5:phpMyAdmin surfaces this as an
ErrorException(SelectStatement.php:614) during table export on PHP 8.5.Fix
Skip expressions without an alias, mirroring the existing
isset($expr->alias) && $expr->alias !== ''guards a few lines above. The null-keyed entry was never read anyway — the only consumer looks up$tables[$thisDb][$expr->table], whose offset is always a non-empty string — sogetAliases()output is unchanged.Notes
PossiblyNullArrayOffsetentry frompsalm-baseline.xml(verified viapsalm --update-baseline; only that entry changed).Utils/Misc.php, which no longer exists —getAliases()was moved intoSelectStatementin Remove Misc class #454 — so this covers the live code path.Tests
getAliasesProvidercase mixing an unaliased table with an aliased one (the null-alias path), asserting unchanged output.phpcs/psalmclean for the change.