docs: English JsonRpcBundle docs, REST and MCP Bundle sections, package cards
en/articles/from-tg/series/php-can-do/named-arguments.md
new file +92
−0
Named arguments
Order no longer matters
- Added in: PHP 8.0
- What it gives you: the ability to pass arguments to functions and methods by specifying their names, not just their values.
What it's about
Before PHP 8 you either had to remember the exact order of arguments or keep peeking at the method signature so as not to mix up which parameter goes after which. And if you needed to pass the last of several optional parameters, you had to pass all of them.
With named arguments you can pass only the parameters you need — by name, and in any order too.
Advantages
- the code becomes more self-documenting — it's clear what each argument means;
- no need to pass a pile of unneeded parameters just to change the last one;
- less risk of mixing up the order;
- easier refactoring — old calls don't break if the order of parameters changes.
Real-world examples
function subscribe(
string $email,
?string $name = null,
?string $language = 'uk',
bool $doubleOptIn = true,
?string $source = null,
?string $tag = null,
bool $sendWelcomeLetter = true,
)
{ /* ... */ }
// before 8.0 you have to pass everything, even what you don't need ❌
subscribe('alex@example.com', null, 'uk', true, null, null, false);
// since 8.0 you can stick to what you need ✅
subscribe('alex@example.com', sendWelcomeLetter: false);
// or even pass the arguments in any order
subscribe('alex@example.com', sendWelcomeLetter: false, tag: 'promo2025');
The remaining parameters take their defaults, and the code reads like a specification of the method call.
An example from a framework (Symfony)
protected function redirectToRoute(string $route, array $parameters = [], int $status = 302): RedirectResponse
{ /* ... */ }
//....
return $this->redirectToRoute(
route: 'user.profile',
status: 301,
parameters: ['id' => $user->getId()]
);
The order of the arguments doesn't matter — what matters is that it's clear what you're setting.
It's worth noting that you shouldn't reorder arguments without a reason just because PHP allows it. If you see places like that in the code, better refactor them and restore the natural order of parameters.
IDEs such as PhpStorm usually highlight such calls for a reason — it's a hint that it's time to tidy up.
Calling an API or SDK
$client->sendMessage(
to: '380501234567',
text: 'Hi 👋',
channel: ChannelsEnum::TELEGRAM,
);
Every argument is visible at once, without comments or documentation.
Conclusion
Named arguments are a configuration-style way of calling functions that makes code readable and safe to change. No more threading a pile of nulls through just to reach the parameter you need.
If a function has more than three parameters — you know what to do.
First published in Ukrainian in the Telegram channel “Created to die” on October 23, 2025.