Forced named parameters

From: Date: Mon, 19 May 2025 15:33:01 +0000
Subject: Forced named parameters
Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi everyone,

Looking [RFC] Clone with v2, especially Larry's message
(https://externals.io/message/127353#127399) I'm thinking that it might be a good idea to allow forcing function calls to use named arguments.

Python has it by defining arguments after the variadic argument:
https://peps.python.org/pep-3102/

  def compare(a, b, *v, key=None):
    ...
Since PHP named args work similarly, borrowing syntax makes sense. It would look like function f(Type $pos1, Type $pos2, ...$v, Type $named1, Type $named2) or without the variadic function f(Type $pos1, Type $pos2, ..., Type $named1, Type $named2) The scope is highly configurable functions and options objects:
    function json_encode(
        mixed $value,
        ...,
        int $depth = 512,
// arguments instead of constants // easier for the code completion // and call strictness
        bool $hexTag = false,
// arguments can be grouped by meaning
        // and new ones can be inserted into the middle
// without breaking compatibility bool $hexAmp = false,
        // options can have values
        string $indent = '    ',
        // ...
    ): string {
        // ...
    }
P.S. I'm just planting an idea for now, unlikely that I'm able to develop it

Thread (5 messages)

« previous php.internals (#127402) next »