Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112959 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 29269 invoked from network); 21 Jan 2021 22:42:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Jan 2021 22:42:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B83DA1804AA for ; Thu, 21 Jan 2021 14:22:44 -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_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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:22:44 -0800 (PST) Received: by mail-wr1-f54.google.com with SMTP id a9so3256076wrt.5 for ; Thu, 21 Jan 2021 14:22:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=Pwz37IFFYs9wgDkfLtoIhsitVUqD0WEIwATksOIvAho=; b=mWZUyNl7g0ZkWmOEAy8W6dMZDxdB7uhYimRy4yD8FLgtj1NtE30wvz4HL5rNJ6HOWY ZOxRRHx+vKsLwNDK/NrsTwYbBBA8cxbV4S+ckxOQFuXuecYIFKNo8pw3Uaa3A9BqKjHe 7NQGLmAq+HhxCdkyqk+SbJQBHz8xF3p1Vh1b5HC8RFI/vwpurXRrlrLteeTPFguEfvhn 1NpUiR/n6R+NlJ2qanS4V7oPJh4E870B8ZcV3HbdvCvkq3Z3K7/OwkYRIycQYKUAzlHu /CypMgLnnBpd3i0igkHG8uUY5Oi0rM4+5HoTacG2vuYM3VXUN8/8lfOOCBj1opR5rFkP qCnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=Pwz37IFFYs9wgDkfLtoIhsitVUqD0WEIwATksOIvAho=; b=XhB+uvg0FgT0HtymL0Xu8+CmklGFxg9IVeWMtnLg83Voa5saHtZqpMIvO9zUjM0zyX NJDrbkYY/7HB9of+GDyrVSOZMvt5/jUfo0WWbP5EELu1TzMlNWh6+bWDzrpW4bSei+jh 5w1UXvgrTGxW50CNcUTu4TOW0UNrxR6zEjcDhtpuRcZoLFSMk3QJO3s8o0cMMdJJIQvC +bus7z8RS02KdzvjYUuXsSiuDgaEOiMpYs9W8uHj2BwnTjgLLaq7ibltaCRQY5EyrJEN ay9yYh1ajwCvtyCzBRKoV6CzCAwGp2wplguz+GeuIP1E/+gUJgbOlgtC88OBH3SeBypM IIcA== X-Gm-Message-State: AOAM532CsMeOw/W7CSBVCMpwxQm4GlYmMwTDbjLft19nI0kWlOXD5EXP 7+hZK0tBFIM2bDTWJT6MNF62iSC2eXQ= X-Google-Smtp-Source: ABdhPJzDxCww8kSUzdWVWbS542LudFKnbhX4DOjsNX2WL6jnccOF3A33rN2uaAZEBGuZENiGg4JlXQ== X-Received: by 2002:a5d:6a4c:: with SMTP id t12mr1448475wrw.249.1611267762602; Thu, 21 Jan 2021 14:22:42 -0800 (PST) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id v1sm9028366wmj.31.2021.01.21.14.22.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Jan 2021 14:22:41 -0800 (PST) To: internals@lists.php.net References: <766fb62e-9413-4472-89be-6557a45c64c8@Spark> <19bd9792-b966-4b8e-af24-a8e4399f7a2f@www.fastmail.com> Message-ID: <2c4d3cfa-7559-5aaa-3fd3-48e2f67af4ab@gmail.com> Date: Thu, 21 Jan 2021 22:22:41 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <19bd9792-b966-4b8e-af24-a8e4399f7a2f@www.fastmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] [RFC] Null Coalescing Assignment in Method Signature From: rowan.collins@gmail.com (Rowan Tommins) On 21/01/2021 21:28, 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. I'm not totally sold on the idea, but I can definitely see why it would be useful. I think a more complex example might show it more clearly: function frobulate(int $id, int $flags = FROB_CLOCKWISE | FROB_MEDIUM_SPEED) {    // ... } Now try to write a function that wraps this in some way, and wants to retain the default for the $flags parameter without hard-coding it. In order to get the default, you have to call the function with fewer arguments: function log_and_frobulate(int $id, int $flags = null) {    log_stuff($id);    if ( $flags === null ) {         return frobulate($id);    } else {        return frobulate($id, $flags);    } } (There's probably other approaches using the "..." argument unpacking operator, but off the top of my head, I can't think of any that avoid the if completely.) If the argument was specified with $flags??=... instead of $flags=... the wrapper doesn't need the extra branch: function log_and_frobulate(int $id, int $flags = null) {    log_stuff($id);    return frobulate($id, $flags); } Regards, -- Rowan Tommins [IMSoP]