Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110387 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55896 invoked from network); 5 Jun 2020 14:58:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Jun 2020 14:58:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 252A21804E0 for ; Fri, 5 Jun 2020 06:40:41 -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-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 ; Fri, 5 Jun 2020 06:40:40 -0700 (PDT) Received: by mail-lf1-f48.google.com with SMTP id z206so5829449lfc.6 for ; Fri, 05 Jun 2020 06:40:40 -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=DjFy9cI04jihZlIUe0lpuTPVyiKvFZ9+IdoZp4F3+Ek=; b=bkYnboJIVfpkS5PCdCyRTa4YwW4vuRAtxw/IwP80mLUMTKbCuePK61OZ3U+PoQsQUd wpSZJXcoxML8rR/FiNHd/UXOOoB2Ls82Dg+Uj26VYgEj5Px7Xe9/zT5+O0LMiYI5uB1c 7hbo0rFNkg91V7LXQ45igr09ptAp06zGDZdaIqhMRBIw2HVjSfUjlfeYWvKsHnyxeCU5 ZMA1errsi77n+rTlfKyCX+U8lOgLDUr8jKNeXurNw8J271lKKMRT6SR3fBL+8pC3UG6u QNvXHIyltOeGJ3Sd1uYoiM5X+nknhv++fp67Rd90FsZplRsJXFX414AAUlqWJuCkqWRP L/+w== 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=DjFy9cI04jihZlIUe0lpuTPVyiKvFZ9+IdoZp4F3+Ek=; b=WZicU0i+oIscugEHaWbkw+yF/AAmbETd0UsA2ToDHM6qvgPD/MAM3mIfSRiM7XSdYn EBq2Ol81CqEk2o8oP3RE6lkPA06ZYrycZsx/BFN60osN58GU0pNdh9eE/KizEPWed119 +TMMxulyTM+rMWVbtlIIhcmQVKv0PR8J7NRMuFfgrZiWfaGYSmDsFRGL6KX6pzax3SFo KW/VIhLQCRCA9eYWPQYDs+sr0OeNV1WEnKW4NyvM/35/KUMsueUX3YnaxibV34NDHss1 WCV9qpZ5hg/Ynm0Ae2Y9wsSShzfEakVsvgvSwZ2wKW5uJ0IJTbh5oXpZicA0Oag9wAhv 4cfQ== X-Gm-Message-State: AOAM533PmrsXhd2OoM/3W6aFmNzlqKo/cgrWN2uvlQAW8Uqn3n/zb8kr alWXZ20bEbS7/zycsilIB/gvjYXf1V1HYzskQd4GWdDBZUY= X-Google-Smtp-Source: ABdhPJx2p1rHpFeN7ebZWmzOaEpp+KSYPo1niJDPHm8nH5k81RVkaNEsifoBDkqCTUOSeGsnao0DjyOzlCnukKyOLrM= X-Received: by 2002:a19:40b:: with SMTP id 11mr5395724lfe.120.1591364438853; Fri, 05 Jun 2020 06:40:38 -0700 (PDT) MIME-Version: 1.0 References: <49D2921E-3A55-4F3B-BF6C-6F6AF84F0CB9@cschneid.com> In-Reply-To: <49D2921E-3A55-4F3B-BF6C-6F6AF84F0CB9@cschneid.com> Date: Fri, 5 Jun 2020 15:40:22 +0200 Message-ID: To: Christian Schneider Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000160eef05a7566806" Subject: Re: [PHP-DEV] [RFC] Named arguments From: nikita.ppv@gmail.com (Nikita Popov) --000000000000160eef05a7566806 Content-Type: text/plain; charset="UTF-8" On Fri, Jun 5, 2020 at 12:45 PM Christian Schneider wrote: > Am 05.05.2020 um 15:51 schrieb Nikita Popov : > > \I've now updated the old proposal on this topic, and moved it back under > > discussion: https://wiki.php.net/rfc/named_params > > First of all I really like this approach to Named Parameters: It seems to > fit well with the rest of PHP. > > Note: I'm using the key: 'value' syntax instead of key => 'value' here but > that's just because I prefer that syntax and think it more naturally > extends to stuff like the shorthand syntax under "Future Scope" but that's > not a prerequisite. > > I have two questions regarding to the Named Parameters which are not > related to the LSP discussion. > They might be restrictions of the current implementation mentioned in the > RFC as opposed to design restrictions: > > 1) Could keywords be allowed as parameter names? Currently using class: > 'foo' throws a syntax error. > 2) Could positional parameters be allowed after named parameters for > variadic functions? > > These two restrictions can be looked at separately and the only reason I'm > bringing them up together is because the use case I'm looking at is HTML > generation with something like a function div() being used as follows. > Please don't discard the two questions just because you don't like this > particular use-case, thank you ;-) > div(class: 'error', > div(class: 'title', "Error Title"), > "Detailed error description...", > ) > > The first issue is probably mainly a parsing issue and changing T_STRING > to identifier seems to fix it though I'm not 100% sure if there are any > drawbacks to this. > Right. It should be possible to use keywords. It's a bit harder than just replacing T_STRING with identifier, but I don't see any fundamental reason why it shouldn't work. > What is the main argument for not allowing positional arguments after > named parameters for variadic functions? > Ambiguities could still be reported if I am not mistaken. > A work-around for the second issue would be to require an artificial > parameter name like content taking a string or array and then do > div( > class: 'error', > content: [ > div(class: 'title', content: "Error Title"), > "Detailed error description...", > ], > ) > but that's somewhat more verbose without any real benefit I can see. > If we ignore the philosophical question of whether having positional parameters after named is a good idea, this mostly comes down to technical complexity. Enforcing the "named after positional" restriction is a simple compile-time check. Without it, we would have to duplicate a large number of argument sending instructions just for this special case. This is basically the same reason why we don't support "foo(...$args, 1)". That's perfectly legitimate code, but supporting it seems like more technical complexity than it's worth. > PS: Concerning "Future Scope: Shorthand syntax for matching parameter and > variable name" I think allowing :$name is reasonable and thinking further > along that line maybe variadic functions separating named from positional > arguments could be done using func(...$positional, ...:$named) similar to > Python's *args, **kwargs). > Separating positional & named variadics / unpacks in that way is certainly a possibility, but I don't think it's the best choice for PHP. In Python this is pretty much required, because Python has distinct list and dictionary types. In PHP these are combined in one data structure, which also allows us to combine them for the purpose of variadics. Combining them makes sure that existing code using variadic forwarding will "just work" with named parameters -- but of course, it also means that some code will accept named parameters even though it was not explicitly designed with that in mind. There's a trade-off there. Regards, Nikita --000000000000160eef05a7566806--