Named arguments: two years later, are you using them
Named arguments landed in PHP 8.0. Two-plus years later, where do you actually use them? Looking for real usage patterns, not the textbook examples.
Most useful for built-in functions with many optional parameters. array_slice($array, offset: 2, length: 5, preserve_keys: true) reads much better than positional. Also useful when skipping optional middle arguments.
In test code I use them extensively with factory methods. User::factory() with named args is clearer than positional even with 2 arguments, especially for optional boolean flags.
The refactoring risk is real: if you rename a parameter, calls using named arguments silently break at runtime (or loudly with type errors). It is a soft API contract. PHPStan 1.10+ detects this.
Constructor promotion with named arguments is my main use case. When creating a value object with 6 fields, named args make the instantiation self-documenting.
I avoid named arguments in library code I publish because parameter renaming becomes a breaking change. In application code the risk is lower since you control all callers.
Useful for calls to functions where argument order is non-obvious or easy to mix up. setcookie(name: $name, value: $value, expires_or_options: $opts) removes the footgun of positional cookie parameter order.
```php blocks are runnable.