Repository navigation
A first sweep of PHPStan 2.3 unused variable/param warning cleanups - #1687
Merged
Merged
Conversation
It should have been removed with commit 26b077d, but was missed.
Quite a few of these are from destructuring where we use some but not all of the elements from the array. Others are just simple dead code.
cpeel
approved these changes
Oct 14, 2026
cpeel
left a comment
Member
There was a problem hiding this comment.
LGTM but one question about a possible readability improvement.
Found by PHPstan 2.3's `foreach.unusedKey` warning.
Mildly surprisingly, with an associative array `$a`,
```foreach ($a as $k => $v) { ... }``` iterates over keys & values, but
```foreach ($a as $v) { ... }``` iterates over values.
In other words, it's equivalent to
```foreach(array_values($a) as $v) { ... }```
Python makes the 'opposite' choice: iterating over a dict yields the
keys:
```for k in a: ...``` is equivent to
```for k in a.keys(): ...```
and
```for v in a.values(): ...```
is equivalent to the PHP.
This is a slightly trickier analysis, but you can see that $prev_text_column_name assigned to at the end of a loop body can only be used in the next iteration of the loop, and it's always assigned to in the 3-way at the start of that loop.
Note that some of these assign a default value to a variable in case there is a path through the if blocks following where it isn't explicitly assigned to. However that's caught by PHPStan's `variable.undefined` warning at level >= 1.
Did this tidyup to avoid PHPStan 2.3's `function.unusedParameter` warning
Found by PHPstan 2.3's new `function.unusedParameter` warning. When we remove the function parameter, PHPstan helpfully shows us the callers that need the extra parameter removed too.
if `empty($datax)`, then `$datax` must be `[]` (because `array_column()` above returns the empty array if the specified column index isn't found. Found by PHPStan 2.3's `assign.overwrite` warning
bpfoley
force-pushed
the
phpstan-2.3-prep
branch
from
October 14, 2026 22:58
d864b80 to
8f6a7d8
Compare
cpeel
approved these changes
Oct 14, 2026
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.
These are mostly obvious and local changes, and let us do a sprinkling of simplification and dead code elimination.
They're unlikely to be wrong, as if they remove variables that are actually used, PHPStan would warn about the use of uninitalized variables.
In the cases where the correctness of the removal isn't obvious, I've pulled them out into separate commits with their own descriptions.