From 1514837104b12d4a95c8ed389ed9fee01cf50c9b Mon Sep 17 00:00:00 2001 From: Ardit Tirana Date: Mon, 22 Jun 2026 15:41:46 +0200 Subject: [PATCH] Avoid using a null alias as an array offset in getAliases() 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. --- psalm-baseline.xml | 3 --- src/Utils/Misc.php | 4 ++++ tests/Utils/MiscTest.php | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 50327a724..10ebc58ed 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1359,9 +1359,6 @@ $tables[$thisDb][$expr->table] - - $tables[$thisDb] - diff --git a/src/Utils/Misc.php b/src/Utils/Misc.php index f4e0bcd83..97a9ca816 100644 --- a/src/Utils/Misc.php +++ b/src/Utils/Misc.php @@ -68,6 +68,10 @@ public static function getAliases($statement, $database) ]; } + if (null === $expr->alias || $expr->alias === '') { + continue; + } + if (! isset($tables[$thisDb])) { $tables[$thisDb] = []; } diff --git a/tests/Utils/MiscTest.php b/tests/Utils/MiscTest.php index 192b22c34..6c775ccbf 100644 --- a/tests/Utils/MiscTest.php +++ b/tests/Utils/MiscTest.php @@ -132,6 +132,25 @@ public static function getAliasesProvider(): array ], ], ], + [ + 'SELECT mytable.a x, o.b y FROM mytable JOIN other o ON o.id = mytable.id', + 'shop', + [ + 'shop' => [ + 'alias' => null, + 'tables' => [ + 'mytable' => [ + 'alias' => null, + 'columns' => ['a' => 'x'], + ], + 'other' => [ + 'alias' => 'o', + 'columns' => ['b' => 'y'], + ], + ], + ], + ], + ], ]; } }