3 ms·
I think named parameters were a mistake for PHP. They weren’t really added for documentation purposes, but to avoid the situation where a function with n argume
by deergomoo 5y ago
I think named parameters were a mistake for PHP. They weren’t really added for documentation purposes, but to avoid the situation where a function with n arguments with default values needs you to specify all the intermediate ones just to override a value at the end.
They’re a great idea in languages designed with them from the start, but adding them to an existing language makes something that was previously a private implementation detail part of the public contract, and only for certain versions of the language. There are already packages that opt out of considering parameters names part of their semantic versioning, effectively demoting it to a “use at your own risk” feature.
I would almost have preferred it to be added only as a special case for built-in features, which are almost all plain functions and have become somewhat unwieldy in places. Third-party code is more often than not object oriented, and so could easily lean on stuff like parameter arrays or fluent interfaces to avoid the ergonomic issues from having tons of parameters.
- conradfr 5y agoI would have preferred a "default" keyword. So given: function foo(string $arg1, int $arg2=2, string $arg3='reddit') {} You could called it like: foo('bar', default, 'HN');