Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112960 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 31420 invoked from network); 21 Jan 2021 22:57:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Jan 2021 22:57:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 378461804C6 for ; Thu, 21 Jan 2021 14:38:08 -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=1.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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, 21 Jan 2021 14:38:07 -0800 (PST) Received: by mail-lf1-f44.google.com with SMTP id a8so4859263lfi.8 for ; Thu, 21 Jan 2021 14:38:07 -0800 (PST) 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=daX69z0pLgVfWTUhWp66YWijbP0nuvNkg9y4J3LK3Dk=; b=DRJbk2qS/zCMDZntqblLl9ZIuuTwpLuVOfrLBysABA4CZ5lOfMhnLjNWTyynMklYUK FSm4JwPXVDhT1N3VH5Y5DKWpaZo9EF8hryYnV/ze/aB3ZJpnssSZHQiKKTydO40FwIt/ 3QJ1Pz908UJxSZMCdR7NypGpFMhWiY4NL0UM7w4K4BnzGzzabTOaz7nuz+NJ/o5We14c G++vX+NazlHqHmsUaj3cQAk+KqvMsu8URPQOZRnibDQdQwclGEts2y0nmoGpiLH/Je6Z wEcwcVztzKzkL7LuYKjhPQYPTA9t5sYUtTiARHDj0+al2AY1HRdsGd6UmkVEBjl+2KTi Zafw== X-Gm-Message-State: AOAM5301khWDPol7z2QhE4F+MIrvKtjesjv2lXM1Cqq6N1Z1NicxQ4WS TpM3QwjDMnGFmeCdUbwAHE3AjO7LSe6pUvkoXV3We4b69yB3+w== X-Google-Smtp-Source: ABdhPJzg0sXk43vwtNYN3ANj1T4MVtUvvhLOrsmmr+AT2nSrHI+oq6k6IiiX+rSKnJ2wKTvQdkiVWSmJYLCP6GMhh28= X-Received: by 2002:ac2:5b4f:: with SMTP id i15mr700668lfp.572.1611268683761; Thu, 21 Jan 2021 14:38:03 -0800 (PST) MIME-Version: 1.0 References: <766fb62e-9413-4472-89be-6557a45c64c8@Spark> <19bd9792-b966-4b8e-af24-a8e4399f7a2f@www.fastmail.com> In-Reply-To: <19bd9792-b966-4b8e-af24-a8e4399f7a2f@www.fastmail.com> Date: Thu, 21 Jan 2021 16:37:53 -0600 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000889f1c05b970b9e8" Subject: Re: [PHP-DEV] [RFC] Null Coalescing Assignment in Method Signature From: pollita@php.net (Sara Golemon) --000000000000889f1c05b970b9e8 Content-Type: text/plain; charset="UTF-8" On Thu, Jan 21, 2021 at 3:29 PM Larry Garfield wrote: > > I'm unclear why you'd allow null at all then. > If you want $bar to be optional, and to be an empty array if not specified, then just do: > > function foo(array $bar = []) { ... } > > At that point, the only thing adding ?array does is allow you to explicitly pass null, > presumably because it has some meaning to your function. > If you don't want that, don't allow it. > Smells a little like it's verging on the `default` proposal that was brought up awhile ago... function foo(int $a, array $b = [], string $c = '') { ... } foo(123, default, "bar"); In this case, foo() never wants `null` as a valid value, but neither does the caller actually want anything different from the default. Allowing a null-coalescish sort of initializer is another potential way to solve this problem, and I'm not here to say I endorse any of them, but maybe that's the intent. -Sara --000000000000889f1c05b970b9e8--