Skip to content

fix(stubs): ArrayObject and ArrayIterator use the PHP 8 parameter names - #14324

Merged
orklah merged 3 commits into
vimeo:masterfrom
jirkace:fix/14130-array-object-param-names
Nov 22, 2026
Merged

orklah merged 3 commits into
vimeo:masterfrom
jirkace:fix/14130-array-object-param-names

Conversation

@jirkace

@jirkace jirkace commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Named arguments with the PHP 8 parameter names of ArrayObject, ArrayIterator and SeekableIterator::seek() report InvalidNamedArgument, because the stubs keep the PHP 7 names.

Before

<?php
$object = new ArrayObject(array: [3, 1, 2]); // InvalidNamedArgument: Parameter $array does not exist on function ArrayObject::__construct
$object->uasort(callback: fn(int $a, int $b): int => $a <=> $b); // InvalidNamedArgument
$iterator = new ArrayIterator([1, 2, 3]);
$iterator->seek(offset: 1); // InvalidNamedArgument

After

$object = new ArrayObject(array: [3, 1, 2]); // no issue

Fixes #14130

vimeo#14130

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: decreased

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 750 104.5 $\color{gray}{\textsf{+0.1\%}}$ 25 908 53 462 682
✅ symfony 3 600 256.5 $\color{gray}{\textsf{+1.5\%}}$ 50 612 $\color{red}{\textsf{+1}}$ $\color{gray}{\textsf{-0}}$ 98 412 $\color{red}{\textsf{+7}}$ 1 528
✅ doctrine-orm 381 19.9 $\color{gray}{\textsf{-0.3\%}}$ 3 481 6 143 0
✅ psl 617 25.0 $\color{gray}{\textsf{+0.4\%}}$ 1 374 $\color{gray}{\textsf{+0}}$ $\color{green}{\textsf{-1}}$ 5 608 $\color{green}{\textsf{-7}}$ 1
✅ phpunit 455 19.6 $\color{gray}{\textsf{-1.7\%}}$ 1 731 3 410 18
✅ php-parser 226 13.3 $\color{gray}{\textsf{-0.4\%}}$ 17 132 21 025 0
✅ tempest 895 36.0 $\color{gray}{\textsf{+0.2\%}}$ 5 047 10 528 252
✅ amphp-amp 68 2.4 $\color{gray}{\textsf{+3.9\%}}$ 29 49 0
✅ webmozarts-assert 272 5.5 $\color{gray}{\textsf{-3.0\%}}$ 577 2 720 0
✅ guzzle-promises 44 2.0 $\color{gray}{\textsf{+0.5\%}}$ 155 434 2
✅ monolog 135 7.5 $\color{gray}{\textsf{-1.0\%}}$ 913 2 479 10
✅ drupal 4 841 252.6 $\color{gray}{\textsf{-1.2\%}}$ 97 587 $\color{red}{\textsf{+1}}$ $\color{green}{\textsf{-5}}$ 169 265 $\color{green}{\textsf{-28}}$ 583
Total 13 285 744.7 $\color{gray}{\textsf{+0.1\%}}$ 204 546 $\color{red}{\textsf{+2}}$ $\color{green}{\textsf{-6}}$ 373 535 $\color{green}{\textsf{-28}}$ 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.
✅ symfony: issues +1 −0

Memory 3 600 → 3 600 MB (<0.1 %) · Wall 252.7 → 256.5 s (+1.5 %)

Weighted 98 405 → 98 412 (+7, +0.01 %): L7 +1

Issue type added removed
ParamNameMismatch 1 0

Added (1)

  • src/Symfony/Component/Form/FormErrorIterator.php:235 ParamNameMismatch (error): Argument 1 of Symfony\Component\Form\FormErrorIterator::seek has wrong name $position, expecting $offset as defined by SeekableIterator::seek
✅ psl: issues +0 −1

Memory 617 → 617 MB (<0.1 %) · Wall 24.9 → 25.0 s (+0.4 %)

Weighted 5 615 → 5 608 (−7, −0.12 %): L7 −1

Issue type added removed
ParamNameMismatch 0 1

Removed (1)

  • packages/iter/src/Psl/Iter/Iterator.php:174 ParamNameMismatch (error): Argument 1 of Psl\Iter\Iterator::seek has wrong name $offset, expecting $position as defined by SeekableIterator::seek
✅ drupal: issues +1 −5

Memory 4 841 → 4 841 MB (<0.1 %) · Wall 255.6 → 252.6 s (−1.2 %)

Weighted 169 293 → 169 265 (−28, −0.02 %): L7 −4

Issue type added removed
ParamNameMismatch 1 5

Added (1)

  • core/lib/Drupal/Component/Utility/DeprecatedArray.php:73 ParamNameMismatch (error): Argument 1 of Drupal\Component\Utility\DeprecatedArray::unserialize has wrong name $serialized, expecting $data as defined by ArrayObject::unserialize

Removed (5)

  • core/modules/jsonapi/src/Normalizer/Value/TemporaryArrayObjectThrowingExceptions.php:236 ParamNameMismatch (error): Argument 1 of Drupal\jsonapi\Normalizer\Value\TemporaryArrayObjectThrowingExceptions::setIteratorClass has wrong name $iteratorClass, expecting $iterator_class as defined by ArrayObje…
  • core/modules/jsonapi/src/Normalizer/Value/TemporaryArrayObjectThrowingExceptions.php:252 ParamNameMismatch (error): Argument 1 of Drupal\jsonapi\Normalizer\Value\TemporaryArrayObjectThrowingExceptions::uasort has wrong name $callback, expecting $cmp_function as defined by ArrayObject::uasort
  • core/modules/jsonapi/src/Normalizer/Value/TemporaryArrayObjectThrowingExceptions.php:268 ParamNameMismatch (error): Argument 1 of Drupal\jsonapi\Normalizer\Value\TemporaryArrayObjectThrowingExceptions::uksort has wrong name $callback, expecting $cmp_function as defined by ArrayObject::uksort
  • core/modules/jsonapi/src/Normalizer/Value/TemporaryArrayObjectThrowingExceptions.php:62 ParamNameMismatch (error): Argument 1 of Drupal\jsonapi\Normalizer\Value\TemporaryArrayObjectThrowingExceptions::exchangeArray has wrong name $array, expecting $input as defined by ArrayObject::exchangeArray
  • core/modules/package_manager/src/InstalledPackagesList.php:56 ParamNameMismatch (error): Argument 1 of Drupal\package_manager\InstalledPackagesList::exchangeArray has wrong name $array, expecting $input as defined by ArrayObject::exchangeArray

head 0421a97 · base c5f4dfd (merge-base) · workflow run

@jirkace

jirkace commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Behaviour change

  • The parameters of ArrayObject, ArrayIterator and SeekableIterator::seek() carry the PHP 8 names ($array, $iteratorClass, $key, $callback, $data, $offset), taken from ReflectionMethod on PHP 8.4; named arguments with them no longer report InvalidNamedArgument. Named arguments with the old names (input:, cmp_function:) now report it, as PHP fails on them.
  • Five neighbouring ArrayObject/ArrayIterator cases ran alone and pass. Not measured: benchmark projects, and the effect on user classes that override these methods; not run: the full suite (CI).

@orklah orklah left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The renames match CallMap_80.php and the perf report confirms it: the removed ParamNameMismatch in drupal/psl are fixed false positives and the added ones (symfony FormErrorIterator::seek($position), drupal DeprecatedArray::unserialize($serialized)) are real PHP 8 mismatches.

One thing needs changing: the offset* methods. ArrayAccess and ArrayObject::offset* carry @no-named-arguments because of conflict with ArrayAccess, since PHP 8 names the parameter $offset in the interface and $key in the classes, and a subclass can't match both. ArrayIterator::offset* has the same conflict but no tag, so this PR moves the ParamNameMismatch from $key overrides to $offset ones, the common name:

<?php
/** @extends ArrayIterator<int, int> */
final class Items extends ArrayIterator {
    public function offsetGet(mixed $offset): mixed { return parent::offsetGet($offset); }
    // master: no issue
    // this PR: ParamNameMismatch: Argument 1 of Items::offsetGet has wrong name $offset, expecting $key as defined by ArrayIterator::offsetGet
}

Could you add the same @no-named-arguments because of conflict with ArrayAccess tag to the four ArrayIterator::offset* stubs, so both names are accepted as for ArrayObject, and add tests for it:

  • a valid case with an ArrayIterator subclass overriding offsetGet($offset) and another overriding offsetGet($key) (php_version 8.0);
  • an invalid case pinning that the old names are now rejected, e.g. $o->uasort(cmp_function: ...) → InvalidNamedArgument.

jirkace and others added 2 commits November 21, 2026 16:31
@jirkace

jirkace commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 0421a97. The four ArrayIterator::offset* stubs carry @no-named-arguments because of conflict with ArrayAccess like ArrayObject's. Tests: arrayIteratorSubclassMayNameTheOffsetParameterLikeArrayAccessOrLikeTheClass ($offset and $key overrides; without the tag it reports ParamNameMismatch) and arrayObjectNamedArgumentsOfPhp7AreRejected (uasort(cmp_function: ...) is InvalidNamedArgument).

After merging master the existing namedArgumentsOfArrayObjectAndArrayIteratorUseThePhp8Names hit DeprecatedMethod for ArrayIterator::uasort (deprecated since 8.6 in PhpDeprecations, reported whatever the analysed version), so that test ignores DeprecatedMethod; it calls the method to check its parameter name. @orklah

@orklah orklah added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 22, 2026

@orklah orklah left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jirkace!

@orklah
orklah merged commit 3355806 into vimeo:master Nov 22, 2026
71 of 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.

Named arguments with PHP 8 parameter names report InvalidNamedArgument on ArrayObject/ArrayIterator

2 participants