Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112883 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 28343 invoked from network); 14 Jan 2021 18:39:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Jan 2021 18:39:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 484E51804D1 for ; Thu, 14 Jan 2021 10:18:15 -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.8 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, MISSING_HEADERS,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-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) (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:18:14 -0800 (PST) Received: by mail-io1-f53.google.com with SMTP id b19so10541377ioa.9 for ; Thu, 14 Jan 2021 10:18:14 -0800 (PST) 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:cc; bh=oS+SNpi68H3862f7d4M9KoPXXUN2aDxUM9iX/qAO2ms=; b=rSrWrC21BkKF1E9CTnwI4VWdPGlCDd8pq08rQdA4KRcq7F0FfRs+HboY07ylkIDZ3p 3PkVIB1o5DLB6zhsAOQWTqF+w+RxEW2kTYQ0RXoJecGB6MglcoUtPunBEkdXRk9Uns8Z xKrr+ICgHAZeL1x/3l1g5e0mkftGh7WKwYz9v3D0QokD4fYxxyC72ds7SxzcPkFnWk0y 2tXdAgJekqBSJsz+ypZ9qZuNGWKvT67hb+PWd/h8XcVYd50eGNl83enLSKlBoTi8lw06 P2rGdmhAiBCNOCM56j0ii+lPs8ea5tIIZcnozKekx37g47XOWlM6JszSY9tUho9jr7Y5 V7UQ== 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:cc; bh=oS+SNpi68H3862f7d4M9KoPXXUN2aDxUM9iX/qAO2ms=; b=sD3XtsIJFdS5saCjdq4nOShzUDSUKHY+oDxivViEfU8S3l0p5G0WoXcaqSA5XRDrzY Z37ZD9aqyx/afE1MYFmFYuvMgsqCy2onkS+yS0waSXF5yrO6BWN1N3DbRSAA9flXWzGM lJxaU/G6C+6bKedVHxsfnJ4BTe6yUYrUrh/d8emuqTCc675Eo/Pf43JJZsC89pc+qZLW 0JD3Jez43/nvi10Ww1ZeeJ8lsmXmVFYjEWRPbI49fVtCZ9Ba/CwRqNKdS5ndQejltlAr BtLuNoNznO6yJi2YvxGYa6GeoDgaP7NgB2L5obRAlnWquisgFI8tcVIOGTrFZT/hfNgm 5KYQ== X-Gm-Message-State: AOAM5317cM+cflWs1f7UeXZZwGmOL5c39FkE22R5ztPEF3Wq8MMW4YSU 5khumVsb5SnS4wev/N6LP95IK29VTpf5wQOOok0TkN39pfumng== X-Google-Smtp-Source: ABdhPJzF9IUWnCCbuFP/6enEHo8A6A7p1gcoFM0h4TgzEcaYkmyCp5Zc9Q6898vJvJbo7lVz7fzG5438zNwexh551ao= X-Received: by 2002:a05:6e02:20ee:: with SMTP id q14mr7441487ilv.259.1610648292577; Thu, 14 Jan 2021 10:18:12 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 14 Jan 2021 18:18:00 +0000 Message-ID: Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000005655cd05b8e0474e" Subject: Re: [PHP-DEV] Feature Proposal From: barel.barelon@gmail.com (Barel) --0000000000005655cd05b8e0474e Content-Type: text/plain; charset="UTF-8" This is handled in a more elegant way by the named arguments of PHP8 https://stitcher.io/blog/php-8-named-arguments With that feature you can just pass the parameters that you need and the others will get their default values Barel On Thu, 14 Jan 2021 at 18:12, Anna Filina wrote: > > 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 > > > --0000000000005655cd05b8e0474e--