Michael Bolli
Michael Bolli

Reputation: 2169

PHP: ArrayObject method signature not compatible with ArrayAccess interface

When I extend an ArrayObject and use vimeo/psalm static analyzer to check my code, I get the following error:

ERROR: ParamNameMismatch
at /var/www/file.php:13:37
Argument 1 of ControllerDescriptionArray::offsetSet has wrong name $key, expecting $offset as defined by ArrayAccess::offsetSet (see https://psalm.dev/230)
    public function offsetSet(mixed $key, mixed $value): void {

This is the file in question:

class ControllerDescriptionArray extends \ArrayObject {
    public function offsetSet(mixed $key, mixed $value): void {
        if ($value instanceof ControllerDescription === false) {
            throw new \InvalidArgumentException('Value must be a ControllerDescription');
        }
        parent::offsetSet($key, $value);
    }

No runtime errors happen, only Psalm is not happy. Anybody knows something about it?

According to https://www.php.net/manual/en/arrayobject.offsetset.php, the ArrayObject::offsetSet() method signature is:

public ArrayObject::offsetSet(mixed $key, mixed $value): void

According to https://www.php.net/manual/en/arrayaccess.offsetset.php, the ArrayAccess::offsetSet() method signature is:

public ArrayAccess::offsetSet(mixed $offset, mixed $value): void

Upvotes: 0

Views: 98

Answers (0)

Related Questions