Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114593 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 54790 invoked from network); 25 May 2021 14:32:13 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 May 2021 14:32:13 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8CCCA1804D8 for ; Tue, 25 May 2021 07:43:30 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 25 May 2021 07:43:30 -0700 (PDT) Received: by mail-lj1-f174.google.com with SMTP id v5so38430957ljg.12 for ; Tue, 25 May 2021 07:43:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IUysybCpsaLrI6AIN20CwKZyI8f1wGNGKB5W9TrjIfQ=; b=lVKmzQp1KkiY42ETK/y0QP5Z6nB69YQrXvAeMAuFa36zAGafHj83tUG20zRpPFHVBq i9yBZ3TK7D8unO7Eg5SxPObsHjP/nAHhm6RoTZkxyMfVuhfpKdt77I55zxSbZBKXZMqI ObN2s0VbvtvLVhnytcOr45hVVtC4L0B7J2nUT6PGv5kauuUpaIPeHafGYotQmMAUF7cC luvs4WkHxb06mRXRWya+HviVTcqeLvhLjFI1b7sd1sIm8DfgpD820EZVsJv4B9AK0JzO XsibnA1nYdahX/ley/KauLcQwA3bpJjU+7dM3SSAkxCe+xcyEHUSsJq5oev3sEMJfP+6 EEQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IUysybCpsaLrI6AIN20CwKZyI8f1wGNGKB5W9TrjIfQ=; b=JC95q9mzQowsRRXlAoRUKHXm2333no7T9pBTNI6ABxjbJwiFratssKczabnl3gAPQ+ 4cSLX3mIFQj+Adx1L3pSGMMfjpikD1pbbXUa5AyCVs6txPdLq2M234pUmQl3+8GjVbog hzojRrZoAIzZVnb8sqCJRHM+E9ewIlzhI2mRGWISt+6NXLADoL6A0baPUG832LZ0h3SO 6soJ4zNThg++jGFEQaU5glxULz+qHUJ6cXDZHgy9szaLoimLPbNEGbjkHe7Q+DboPOM6 jfsprcP6sDszpQuPxkKjHhUMdEE5nYFNffE6mCAfOmHM7Be7bn5I67pjM0vNmnJ21bSL XZIg== X-Gm-Message-State: AOAM532otRuPeelqUjxKTkSpP5v2OhIj95A4iLr4WuscWkeGiV0XH2W1 Zm41V93a+p+fQxJ2SUVKlb74voRpC384kMOeJaY= X-Google-Smtp-Source: ABdhPJynqk+xp7EP/J2vK3bp30AsMaatFNmFdaJbJ3AKd1kEHyzSQbaAwPTWI2TVIosLsxi8xsiQHNsbl2wg5leJUkA= X-Received: by 2002:a05:651c:50f:: with SMTP id o15mr20865114ljp.452.1621953808368; Tue, 25 May 2021 07:43:28 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 25 May 2021 16:43:12 +0200 Message-ID: To: Levi Morrison Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000097085d05c3288c6d" Subject: Re: [PHP-DEV] Allow combining arg unpacking and named args From: nikita.ppv@gmail.com (Nikita Popov) --00000000000097085d05c3288c6d Content-Type: text/plain; charset="UTF-8" On Tue, May 25, 2021 at 4:36 PM Levi Morrison wrote: > On Tue, May 25, 2021 at 8:18 AM Nikita Popov wrote: > > > > Hi internals, > > > > Currently, argument unpacking (...$foo) cannot be combined with named > > arguments (foo: $bar) at all. Both func(...$args, x: $y) and func(x: $y, > > ...$args) are rejected by the compiler. > > > > https://github.com/php/php-src/pull/7009 relaxes this by allowing > > func(...$args, x: $y). The named arguments are required to come last, > > because this automatically enforces the invariant that named arguments > must > > be sorted after positional argument. > > > > Are there any concerns with relaxing this restriction? > > > > Regards, > > Nikita > > How do named parameters interact with the variadic parameter? > > function f(...$params) { var_dump($params); } > $args = [1, 2, 3]; > f(...$args, params: [4, 5, 6]); > Ah, I think I should have mentioned that the proposed change doesn't actually allow you to do anything new or different -- it only removes an arbitrary syntactical limitation. In particular func(...$args, x: $y) will behave the same as func(...[...$args, 'x' => $y]); with the only difference that if $args already contained an 'x' key, that would be an error, instead of silently ignored. So to answer your question: Variadic parameters are not targetable by named parameters, so what you wrote will pass [1, 2, 3, 'params' => [4, 5, 6]] as usual. Regards, Nikita --00000000000097085d05c3288c6d--