Skip to content

Count a write through an ArrayAccess offset as a use of the object - #14410

Merged
danog merged 1 commit into
vimeo:masterfrom
danog:array-access-write-uses-receiver
Nov 20, 2026
Merged

danog merged 1 commit into
vimeo:masterfrom
danog:array-access-write-uses-receiver

Conversation

@danog

@danog danog commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Psalm 7.13.0 reports a parameter or variable that is only written through an ArrayAccess offset as unused.

Before

<?php
function push(Bag $bag): void { $bag[] = "a"; } // UnusedParam
function set(Bag $bag): void { $bag[1] = "a"; } // UnusedParam
function setArrayObject(ArrayObject $object): void { $object["k"] = "a"; } // UnusedParam
function setLocal(): void { $bag = new Bag(); $bag[] = "a"; } // UnusedVariable

After

function push(Bag $bag): void { $bag[] = "a"; } // no issue
function set(Bag $bag): void { $bag[1] = "a"; } // no issue
function setArrayObject(ArrayObject $object): void { $object["k"] = "a"; } // no issue
function setLocal(): void { $bag = new Bag(); $bag[] = "a"; } // no issue

The offsetSet() and offsetUnset() calls of `$a[] = $v` and `unset($a[0])` reuse the type of
their receiver since 64678f4, which skipped the read of the receiver recording its use: a
parameter or variable only written through an offset was reported unused.
@danog danog added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 768 58.5 $\color{gray}{\textsf{+0.3\%}}$ 25 926 53 515 682
✅ symfony 3 606 179.5 $\color{gray}{\textsf{-0.2\%}}$ 50 607 98 402 1 528
✅ doctrine-orm 393 22.8 $\color{gray}{\textsf{-4.0\%}}$ 3 480 6 161 0
✅ psl 632 29.7 $\color{gray}{\textsf{+1.0\%}}$ 1 299 5 455 1
✅ phpunit 471 19.6 $\color{gray}{\textsf{+0.3\%}}$ 1 744 3 459 18
✅ php-parser 236 13.2 $\color{gray}{\textsf{-0.5\%}}$ 17 133 21 035 0
✅ tempest 905 34.4 $\color{gray}{\textsf{+0.6\%}}$ 5 043 10 505 252
✅ amphp-amp 61 1.7 $\color{gray}{\textsf{-1.2\%}}$ 29 49 0
✅ webmozarts-assert 288 3.8 $\color{gray}{\textsf{+0.5\%}}$ 577 2 720 0
✅ guzzle-promises 56 1.7 $\color{gray}{\textsf{+1.2\%}}$ 154 427 2
✅ monolog 153 4.7 $\color{gray}{\textsf{-1.3\%}}$ 903 2 403 10
✅ drupal 4 851 158.2 $\color{gray}{\textsf{+5.4\%}}$ 97 526 169 112 583
Total 13 420 527.9 $\color{gray}{\textsf{+1.4\%}}$ 204 421 373 243 3 076
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +20 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count over all categories, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted (types): type issues weighted by error level (levels 1–8 as is, always-errors 10, strictness checks 1). Taint and dead-code issues are not weighed. The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Taint: head count of Tainted* issues, then $\color{orange}{\textsf{+added}}$ $\color{orange}{\textsf{-removed}}$ against base. Both are orange as either direction needs review: more can be new detection or false positives, fewer can be fixed false positives or lost detection.
  • Dead code: head count of unused-code issues, shown only when a run reported some (findUnusedCode). More is red, fewer is green.
  • Total: sum over the projects compared on both sides. Thresholds apply per project, not to the total.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{orange}{\textsf{orange}}$ needs review, $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Types (heading): direction of the total weighted change, increased · decreased · unchanged. Taint and Dead code (heading): added and removed counts, present only when non-zero. Informational, never fails the check.

head a83bcdc · base cd987ac (merge-base) · workflow run

@danog
danog merged commit a328b90 into vimeo:master Nov 20, 2026
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:fix The PR will be included in 'Fixes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant