Quick quiz: what does processOrder($order, true, false, true, false, false) do?
You have no idea. Neither do I. And neither will you in three months when you come back to debug this code.
I used to think this was just “how PHP worked” — positional parameters, take it or leave it. Then PHP 8.0 dropped named parameters, and suddenly that cryptic boolean soup became self-documenting code.
Here’s the before and after:
// Before: positional boolean hell
function processOrder(
Order $order,
bool $validateStock = true,
bool $sendEmail = false,
bool $applyDiscount = true,
bool $updateInventory = false,
bool $logActivity = false
) {
// ...
}
// What does this even mean?
processOrder($order, true, false, true, false, false);
// After: PHP 8 named parameters
processOrder(
order: $order,
validateStock: true,
applyDiscount: true
);
// Or when you need to flip a flag deep in the parameter list:
processOrder(
order: $order,
sendEmail: true,
logActivity: true
);
The beauty of named parameters is that you skip the defaults you don’t need. No more passing null, null, null, true just to reach the parameter you actually want to change.
This isn’t just about readability (though that’s huge). It’s about maintenance. When you add a new optional parameter, existing calls don’t break. When you reorder parameters (carefully!), named calls stay stable.
Rule of thumb: if you have more than two boolean parameters, or any boolean parameter after the first argument, use named parameters at the call site. Your code reviewers will love you.
PHP 8 is six years old now. If you’re not using named parameters yet, you’re missing out on one of the best DX improvements PHP has ever shipped.

Leave a Reply