psalm
psalm copied to clipboard
Not possible to extend `ArrayObject` - conflict of ArrayObject/ArrayAccess?
Example: https://psalm.dev/r/a03704b816
And the real code:
/**
* Class ControllerDescriptionArray.
*
* @extends \ArrayObject<int, ControllerDescription|null>
*/
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);
}
}
output (psalm 5.18.0):
ERROR: ParamNameMismatch
at /var/www/framework/src/controller/description/ControllerDescriptionArray.php:13:37
Argument 1 of mbolli\framework\controller\description\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 {
ERROR: ParamNameMismatch
at /var/www/framework/src/controller/description/ControllerDescriptionArray.php:13:37
Argument 1 of mbolli\framework\controller\description\ControllerDescriptionArray::offsetSet has wrong name $key, expecting $offset as defined by ArrayObject::offsetSet (see https://psalm.dev/230)
public function offsetSet(mixed $key, mixed $value): void {
Note: 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