Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending ArrayObject and overwriting offsetSet leads to unsolvable ParamNameMismatch error #10479

Closed
marcreichel opened this issue Dec 12, 2023 · 3 comments · Fixed by #10480

Comments

@marcreichel
Copy link

marcreichel commented Dec 12, 2023

PHP: 8.2.13
Psalm: 5.16.0/5.17.0

We have a class which extends ArrayObject and overwrites the offsetSet method.
The method has the two arguments $key and $value as defined in ArrayObject. ArrayObject itself implements ArrayAccess where the method signature is different already.

We now have three errors (since Psalm 5.16.0):

  • Argument 1 of Our\Class::offsetSet has wrong name $key, expecting $offset as defined by ArrayAccess::offsetSet (see https://psalm.dev/230)
  • Argument 1 of Our\Class::offsetSet has wrong name $key, expecting $index as defined by ArrayObject::offsetSet (see https://psalm.dev/230)
  • Argument 2 of Our\Class::offsetSet has wrong name $value, expecting $newval as defined by ArrayObject::offsetSet (see https://psalm.dev/230)

Error 1 and 2 contradict each other. And error 3 makes no sense (imho) because the argument is called $value in both ArrayObject and ArrayAccess.

The errors exist since version 5.16.0. Downgrading to 5.15.0 "solves" the problem.

Copy link

Hey @marcreichel, can you reproduce the issue on https://psalm.dev ?

@marcreichel
Copy link
Author

Copy link

I found these snippets:

https://psalm.dev/r/b6bf67060d
<?php

/**
 * @template array-key
 * @template TValue
 * @template-extends ArrayObject<array-key, TValue>
 */
class OurClass extends \ArrayObject
{
    public function offsetSet($key, $value): void
    {
        parent::offsetSet($key, $value);
    }
}
Psalm output (using commit a75d26a):

ERROR: ParamNameMismatch - 10:31 - Argument 1 of OurClass::offsetSet has wrong name $key, expecting $offset as defined by ArrayAccess::offsetSet

ERROR: ParamNameMismatch - 10:31 - Argument 1 of OurClass::offsetSet has wrong name $key, expecting $index as defined by ArrayObject::offsetSet

ERROR: ParamNameMismatch - 10:37 - Argument 2 of OurClass::offsetSet has wrong name $value, expecting $newval as defined by ArrayObject::offsetSet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant