Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110386 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 29440 invoked from network); 5 Jun 2020 12:02:58 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Jun 2020 12:02:58 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 72A1D1804B7 for ; Fri, 5 Jun 2020 03:45:38 -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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS1836 195.49.0.0/17 X-Spam-Virus: No X-Envelope-From: Received: from darkcity.gna.ch (darkcity.gna.ch [195.49.47.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 5 Jun 2020 03:45:37 -0700 (PDT) Received: from flatter.home (unknown [IPv6:2a02:1205:34fb:29c0:c24:85c:cc90:b94c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by darkcity.gna.ch (Postfix) with ESMTPSA id 4F7EB6C1518; Fri, 5 Jun 2020 12:45:35 +0200 (CEST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) In-Reply-To: Date: Fri, 5 Jun 2020 12:45:34 +0200 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <49D2921E-3A55-4F3B-BF6C-6F6AF84F0CB9@cschneid.com> References: To: Nikita Popov X-Mailer: Apple Mail (2.3608.80.23.2.2) Subject: Re: [PHP-DEV] [RFC] Named arguments From: cschneid@cschneid.com (Christian Schneider) 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 =3D> '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. 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. 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). - Chris