Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110008 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 9113 invoked from network); 5 May 2020 17:09:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 May 2020 17:09:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 21E271804D3 for ; Tue, 5 May 2020 08:44:56 -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,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE 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-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.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 ; Tue, 5 May 2020 08:44:55 -0700 (PDT) Received: by mail-wm1-f48.google.com with SMTP id x4so2839873wmj.1 for ; Tue, 05 May 2020 08:44:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beberlei-de.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=O5vi+4nMnOCdNN99G/0jxvfiPJko5JLZA1Z+fZHTeac=; b=yyH/SfqtWd87zvTbxiKOathT3vu8oQVWEcplYkYwbtR5/DJocHXji28Ci/4ElEiTQ2 KCAZY1WjzvUFoO8iZU4I5qZytvdo/CEtO23v/6N44psVc4qj702DSTPCRXqLj+csRfPt oLxDbLd2zCnHbJs1yGfTgUlH7Ik4SyVBnHrfFazTqr74/T/w90zmyGFsOHUvf0Maefzc p/mTN/YPX0H4IwMgBbSUM7V3k/wOZm+uotclnpZDVbvIlx8yR9G33JUubXr58trnjMte JwzrM5ZRTyzPbaA1EJw3SdjS61rD+oB62XtDXtqLCMA95iSMGkkE9kL85b+iVloXzXDi cbBw== 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=O5vi+4nMnOCdNN99G/0jxvfiPJko5JLZA1Z+fZHTeac=; b=dy65kTaIhbT36FNeLekwSykduoYrNqzisRzo+ax7N5LR7Wa3hGq1Ycq+qjk5lCpg4j ZYrUKJ7wVyYs6pbngDHn409JSZZTQjjxkI7dx1GlimpFbO1N/HMdseeSXa8vpD70f5Df j+ExEzT20K/N8mcBZTlU+Il3R0uFGfGUG+Skx/PzQkf1hp7MHnHwW0qw3ox1RZjPknUD l17zzVZhUhT1hpczV7GHBAWOV/A75v4miQ8++g+mHUy30vpjqm476eD4zzW3NjVKfdqB yiOgCcehBJWP3/Wz8TapHse3rut4yALBPgi6FilyNOQ7NE72Zs7TQP06yVZTxC8TlHLG nwaw== X-Gm-Message-State: AGi0PuaXGkBKoxor9+08Gu53QaPa01rQJ/IIANnYdXGFy8uoN+ifm3sD rsc8pitKlWV0N4OQiIEf31shibyjQDoieeeeNT4HCg== X-Google-Smtp-Source: APiQypJ01aOtluevRf2H4tLBlA6TRh/f0C69ILpCPoX+dkLvolC73W9Ys2hieVPoBx7gmFxA406UfZEsfBJg2ORfTuA= X-Received: by 2002:a7b:c0d5:: with SMTP id s21mr4115777wmh.107.1588693491656; Tue, 05 May 2020 08:44:51 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 5 May 2020 17:44:40 +0200 Message-ID: To: Marco Pivetta Cc: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary="0000000000003a3e0205a4e88705" Subject: Re: [PHP-DEV] [RFC] Named arguments From: kontakt@beberlei.de (Benjamin Eberlei) --0000000000003a3e0205a4e88705 Content-Type: text/plain; charset="UTF-8" On Tue, May 5, 2020 at 4:11 PM Marco Pivetta wrote: > Hey Nikita, > > On Tue, May 5, 2020 at 3:51 PM Nikita Popov wrote: > > > Hi internals, > > > > I've recently started a thread on resurrecting the named arguments > proposal > > (https://externals.io/message/109549), as this has come up tangentially > in > > some recent discussions around attributes and around object ergonomics. > > > > I've now updated the old proposal on this topic, and moved it back under > > discussion: https://wiki.php.net/rfc/named_params > > > > Relative to the last time I've proposed this around PHP 5.6 times, I > think > > we're technically in a much better spot now when it comes to the support > > for internal functions, thanks to the stubs work. > > > > I think the recent acceptance of the attributes proposal also makes this > a > > good time to bring it up again, as phpdoc annotations have historically > had > > support for named arguments, and this will make migration to the > > language-provided attributes smoother. > > > > As mentioned some days ago, I see named parameters as an added liability, > rather than values. > The rationale of my negativity around the topic being that a diff like > following is now to be considered a BC break: > > ```diff > -function foo($parameterName) { /* ... */ } > +function foo($newParameterName) { /* ... */ } > ``` > > In addition to that, the feature seems to be especially designed to work > with particularly bad API (anything with a gazillion optional parameters, > such as all the OpenSSL nightmares in php-src). > I see the PHP internal API as the main benefactor of this feature over userland code imho. Internals realistically couldn't get "smaller APIs" without adding many new functions instead, for example htmlspecialchars. The trade off from API design perspective is either providing a more complex API by having function permutations or an OOP API, which in turn developers have more trouble remembering. Or the more beginner approachable way is providing a single function that is easy to remember exists, but in turn does more things and may require a look into the documentation to see all the options. Given we have this API already in PHP and this will not realistically change, I think named params will be a big win. > In practice, the issues around bad API (in this case, ba > d = lots of > optional parameters, maybe even ordered arbitrarily) are fixed by using > proper value types and structs or value objects: > > ```php > myHorribleLegacyAndOrganicallyGrownApi( > > > ...MyInfiniteSequenceOfParametersAsProperValidatedStructure::fromArray($stuff) > ->toSequentialParameters() > ); > ``` > > For the few use-cases where this is needed, the userland solution seems to > be sufficient, without introducing catastrophic BC boundary expansions. > In this example $stuff is an array which has keys. Presumably $parameterName => $newParameterName would be equivalent to a change of key names. Or property names on MyInfiniteSequenceOfParametersAsProperValidatedStructure. So you get the BC break of renaming anyways in your example. Now as a provider of a public API (library, framework) you can still counter this with a BC layer: function foo($newParameterName, $parameterName = null) { if ($parameterName !== null) { $newParameterName = $parameterName; trigger_error("Using paramaterName as named parameter is deprecated, use newParameterName instead.", E_USER_DEPRECATED); } /... } this looks ugly (because we haven't seen it before), but is not more or less complex than the same BC / deprecation layer in fromArray with changed option: public static function fromArray(array $options) { if (isset($options['parameter_name'])) { $options['new_parameter_name'] = $options['parameter_name']; trigger_error("Using paramaeter_name as option is deprecated, use new_parameter_name instead.", E_USER_DEPRECATED); } } So nothing much would technically change for someone who cares about BC for their users. > > > Unless I'm not seeing an incredible (hidden, to me) value from this > functionality, this is a clear -1 from me. > > Marco Pivetta > > http://twitter.com/Ocramius > > http://ocramius.github.com/ --0000000000003a3e0205a4e88705--