1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 17:52:45 +01:00
psalm/docs/running_psalm/issues/NamedArgumentNotAllowed.md
AndrolGenhald de5a031088
Improve @no-named-arguments support and variadics. (#5455)
* Improve @no-named-arguments support and variadics.

Handling of argument unpacking and variadics still needs a pretty big makeover, but this is a good start.

Fixes #5420
Improves #5453 (iterable works, array still causes issues)

* Remove unneeded imports.
2021-03-22 19:58:22 -04:00

656 B

NamedArgumentNotAllowed

Emitted when a named argument is used when calling a function with @no-named-arguments.

<?php

/** @no-named-arguments */
function foo(int $a, int $b): int {
	return $a + $b;
}

foo(a: 0, b: 1);

Why this is bad

The @no-named-arguments annotation indicates that argument names may be changed in the future, and an update may break backwards compatibility with function calls using named arguments.

How to fix

Avoid using named arguments for functions annotated with @no-named-arguments.

<?php

/** @no-named-arguments */
function foo(int $a, int $b): int {
	return $a + $b;
}

foo(0, 1);