Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112957 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 23791 invoked from network); 21 Jan 2021 21:48:58 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Jan 2021 21:48:58 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 787231804A7 for ; Thu, 21 Jan 2021 13:29:17 -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=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 21 Jan 2021 13:29:16 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 014DB5C021D for ; Thu, 21 Jan 2021 16:29:16 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Thu, 21 Jan 2021 16:29:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=M9F4doGf/L2eQ0Hq3/IsTCWaluOJgxPJN4MbNrlCe aM=; b=BughPkOiR9w83O8OmnIA/B8MVveyo1WhCqJZrWS1epQaI5kioLwgpKWXl F5pINQRSq7x8Vv64V+t4tbBm7uXbpC8d7+6pUVVCbptuQqrTZ3eDQ99fE5rAwbar U9/NVqQZVc0ZVHpCIQW61rM4GKpkLmPS1EiE7EzCXrOlTq9AEB8QCQ9cENHovhCz VzKRMNbTl+y6ZKEOtTtfc8D9dCfrpcHfKOKMtkCJcKKVx7bIKnCWEmNOQOz7Il5D b83zibdbbUWGPjQ8szsDLhWEergYzEMPiRva73/3DuZ0MIMCa9sOP3H5p5GYr4oP cRA4oqfhZuza5JUJyxAYOPmTOoO7Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudeggdduhedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id A8EDC14200A2; Thu, 21 Jan 2021 16:29:15 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-78-g36b56e8-fm-20210120.001-g36b56e88 Mime-Version: 1.0 Message-ID: <19bd9792-b966-4b8e-af24-a8e4399f7a2f@www.fastmail.com> In-Reply-To: <766fb62e-9413-4472-89be-6557a45c64c8@Spark> References: <766fb62e-9413-4472-89be-6557a45c64c8@Spark> Date: Thu, 21 Jan 2021 15:28:55 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Null Coalescing Assignment in Method Signature From: larry@garfieldtech.com ("Larry Garfield") On Thu, Jan 21, 2021, at 5:51 AM, Daniel Simkus wrote: > Hello all, >=20 > I am writing to see if anyone is interested in an RFC for ability to=20= > automatically coalesce nullable method parameters with the supplied=20= > default. It would look something like this: >=20 > function foo(?array $bar ??=3D []) { >=20 > This would result in $bar automatically converting to an array if null= =20 > is passed, as opposed to either having to do a null check before the=20= > function call and not passing parameter at all - or alternatively=20 > having to do something like: >=20 > function foo(?array $bar =3D []) { > =C2=A0=C2=A0 =C2=A0$bar ??=3D []; >=20 >=20 > I don=E2=80=99t see this creating any BC incompatibilites and the ??=3D= syntax is=20 > something already in use in PHP since 7~ >=20 > I don=E2=80=99t have any experience with C, so would ideally love it s= omeone=20 > could help with the development with this, or maybe point me in the=20= > right direction. >=20 > I would also require RFC Karma if people are interested in opening a=20= > discussion about this (dansimkus) >=20 > Thank you all for your time >=20 > Regards, > Daniel Simkus I'm unclear why you'd allow null at all then. If you want $bar to be op= tional, and to be an empty array if not specified, then just do: function foo(array $bar =3D []) { ... } At that point, the only thing adding ?array does is allow you to explici= tly pass null, presumably because it has some meaning to your function. = If you don't want that, don't allow it. --Larry Garfield