In order to use named parameters, somebody needs to have declared
what those names are, and made them a stable API. If they're
automatically supported on existing functions, the author might not
intend them to be used, or even realise they can, so not keep them
stable (I tend to think of parameter names as local, not contractual).
Wouldn't using the name of the variable that is already used for its
function signature work perfectly fine for this?
This is how IDEs already hint for function call completion.
Yes, that's what I meant by "automatically supported on existing
functions". The problem I was highlighting is that right now, I can
write this in version 1.0.0 of a library:
function foo($id) {
$blobId = $id;
doSomething($blobId);
}
And change it to this in version 1.0.1, without violating SemVer:
function foo($blobId) {
doSomething($blobId);
}
The name of the parameter is an implementation detail, not a contract.
If named parameters are automatic, that suddenly becomes a breaking
change, and either every library author recognises that and avoids such
changes, or every library user has to check documentation to see if it's
safe to use named parameters.
Worse, as highlighted in the 2013 RFC, parameter names aren't checked
when over-riding a method, like this:
interface Fooable { public function foo(int $id); }
class Blob implements Fooable { public function foo(int $blobId) { ... } }
So either the first version of PHP to support named parameters would
require library authors to change any such code, or again the library
user has to check if it's safe to use named parameters.
The alternative is to make named parameters opt-in on the part of the
function author, using extra syntax in the function declaration. I think
that's a better approach, but probably means an even longer wait until
libraries introduce it.
So realistically, even if named arguments were added right now, they
couldn't reliably be used to skip over default parameters in existing
functions.
None of this is a problem with a simple "default" keyword, which would
work reliably with all existing function signatures where a default is
defined, and require no change in code or practice on the part of
library authors, so can be introduced right now, and used straight away.
Regards,
--
Rowan Collins
[IMSoP]