Hi Andreas,

On 27/07/2020 00:41, Andreas Hennings wrote:
1. Calls with named arguments can only happen on:
   - explicitly named functions (e.g. no call_user_func()).
   - constructor calls with an explicitly named class.
   - object methods, if the object variable is type-hinted or a type is
known at compile time.
2. Named arguments in calls are converted to number-indexed arguments at
compile time.
3. Parameter name lookup is done based on the type-hinted class or
interface. Parameter names on the actual object are ignored.


While this is an interesting concept in general, it introduces a much larger change to the semantics of the language than seems justified for this particular problem - it would effectively require introducing an element of "static typing" into the language.

By "static typing", I mean this:

> variables have an intrinsic type, and the same value can behave differently depending on the type of variable that holds it

Which could be contrasted with "dynamic typing" like this:

> values have an intrinsic type, and operations will be selected based on those values, regardless of which variables hold them

Although we have various type annotations in the language now, they are all just restrictions on the types of value a variable can hold; they don't change the behaviour of that value. With this proposal, these two function would potentially do different things when given the exact same argument:

function a(FooInterface $arg) { $arg->doSomething(namedparam: 42); }
function b(BarInterface $arg) { $arg->doSomething(namedparam: 42); }


Static typing of that sort is a useful feature of other languages, and there are people who'd love to see PHP go that way, but it's not something we should bolt on in a hurry just to solve an issue with named parameters.


Regards,

--
Rowan Tommins (né Collins)
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to