Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112882 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 26868 invoked from network); 14 Jan 2021 18:34:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Jan 2021 18:34:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6D7C118050B for ; Thu, 14 Jan 2021 10:12:47 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HTML_IMAGE_ONLY_32,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-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 ; Thu, 14 Jan 2021 10:12:46 -0800 (PST) Received: by mail-lj1-f182.google.com with SMTP id w26so7527295ljo.4 for ; Thu, 14 Jan 2021 10:12:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to:cc; bh=wNLjW3YSVfyHqrzPFju3CsiGcSJGmUi08X2DsC9uDio=; b=QmL90HXjG3xfZa6nOmY/C9hCRHy4XNGrUZYC5Ck0uPWZhx4TnF9w8AB6wAxfgf0gsA cuvxfyJ4EAXDOrTGegxZ3ync08XBreZvuKk8BTdRG7w8WW4JMZN49zTTgNbSOV49tyrK lHQaHeCxbedus3JBvo/+kJXUVh2szhP+GBxr/N0pWP189zYU6SYi6h6NbSzCWaQu3y0H BYv3nCojMBRw8do/gKaH0807y9yaVG9r9ZxOeE5K0kUOCxOsS3mI4+pbG1CHZgClK1Y3 2UKvtHCW9scg+qHtMVXrojss8r2D3RNul/vylN2qWAqCik+d7aHbDUvyH++guB8nOMAi /Zxw== 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:reply-to :from:date:message-id:subject:to:cc; bh=wNLjW3YSVfyHqrzPFju3CsiGcSJGmUi08X2DsC9uDio=; b=TbCif/oUnuuF9VsO6w99DDCdID0KTYBJt5WIX5cGoblBw78WnQPOIgjbW+8I7g3fm/ iTbGkXEH4lMbIyY8Qh59V6xP0E9Ah8wshol+lOfszBA+Am0R4bDRcr7Hd/Mbhr7v24Ct tT5jAJupBDRWCUjkWxzH2/XDkC7+xjQJT54idp/sh+jq8H5MPKaW4eG4MNZUi5siCwRU qWYmrjWw2MvTnm39CLdMZO4AYAPlWUV5ez3n5Hv5RT0Xk7i3hxdQaR1buQGmYD+EnQXD QcsJYxxQI87gTKv5GsSm30DlJABI9+djhILSk9TNfJWwatMKg0BueQuwhESbXRvZqCY0 q8NA== X-Gm-Message-State: AOAM531+/RjsiRkprN1VxmDIPre8haYWzMBmVLifTS8ees/KhDFv3ZbU JVjCm0IsFofs8Fda0SLQf/yG9UzvUyyxUuW9oxs= X-Google-Smtp-Source: ABdhPJyw+lNhD+WbNgGHLtfz45piRR5Oem16JJd1jh2e9dMHzIxIQN9isCp/T21OejLU3LUUySpSyyv7OsB77NkFXJY= X-Received: by 2002:a2e:8ec7:: with SMTP id e7mr3624100ljl.249.1610647963426; Thu, 14 Jan 2021 10:12:43 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Reply-To: me@afilina.com Date: Thu, 14 Jan 2021 13:12:34 -0500 Message-ID: To: Andrew Brown Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000b7e2d705b8e033b0" Subject: Re: [PHP-DEV] Feature Proposal From: afilina@gmail.com (Anna Filina) --000000000000b7e2d705b8e033b0 Content-Type: text/plain; charset="UTF-8" > So if some calling code wants to override a later parameter, it currently needs to pass a value to the earlier optional parameters. I think that this is a code smell that should be addressed by a better design. Here's a detailed explanation of why one should use default parameters sparingly, along with alternatives: https://afilina.com/null-hell I feel like such a feature would enable developers to dig themselves a deeper hole towards unmaintainable code. That's just my 2 cents. Anna Filina On Thu, Jan 14, 2021 at 12:52 PM Andrew Brown wrote: > This is my first foray into PHP internals, so please let me know if I'm > doing something wrong. Currently just following the instructions from > https://wiki.php.net/rfc/howto. > > Currently this proposal is only a "concept". > > I propose we add a "default" keyword that can be passed as an argument > into a function/method call. This would allow the calling code to defer to > the function signature for the value of a parameter. > > Traditionally, all optional parameters are placed towards the end of the > function parameter list, but as we all know, sometimes this order can be > tricky. So if some calling code wants to override a later parameter, it > currently needs to pass a value to the earlier optional parameters. > > A current solution around this is to define all defaults in the body of > the function rather than in the signature. > > [image: Screen-Shot-2021-01-14-at-11.45.09-AM.jpg] > > However, this adds some extra boilerplate, and we can't use default > parameters as they were really intended. > > My proposal is to add a new `default` keyword to be passed as an argument. > > [image: Screen-Shot-2021-01-14-at-11.44.57-AM.jpg] > > The first call of the function here is how we currently have to do things. > We have to explicitly pass `true` in as the second parameter. > > However, in the second call, we now use the new `default` keyword, which > will defer to the function signature for the default value of `$param2`. > > Thanks all, looking forward to some feedback! > > -- > Andrew M. Brown > --000000000000b7e2d705b8e033b0--