Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113235 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 2736 invoked from network); 23 Feb 2021 17:39:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Feb 2021 17:39:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CB0931804B3 for ; Tue, 23 Feb 2021 09:28:25 -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 out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (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 ; Tue, 23 Feb 2021 09:28:25 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id F0A845C00ED for ; Tue, 23 Feb 2021 12:28:23 -0500 (EST) Received: from imap8 ([10.202.2.58]) by compute4.internal (MEProxy); Tue, 23 Feb 2021 12:28:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=fm2; bh=CHdE6S IpNiRjE7985QfaeIpHDo1+PoWg/CejoAC/DQE=; b=LDuS10uis40tNS5/wnp+g6 NJcbF3GtI7mCOliMqxV8zEGQxwGxBuHHr8pDk6u4Z8O+uCqEqiDgXE1KEvP/cWl2 qYSHkQIw/33ttfX32V56fxioIkchttB5xTNyL6ISFk28HnHvCO/6ptYAjjHX6SW1 M841k5XKsR+AgF95crsBxIjkpTLKxT/LwwITa3iVyp4sXVft19/IiZw7IyYJbt3u kNpISGYavaPCADi5viS7Gv8g62raq3If3Eh7z+2CiavItFLDopd+J0k18EJiHy1y fl5cJliUfC0Qr4xN7Ven0XK3W5Fha67t4BAo3em7/R11Psv4jGxnsu/K2/+2qXng == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrkeehgddutddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 64AF73A00B8; Tue, 23 Feb 2021 12:28:23 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-141-gf094924a34-fm-20210210.001-gf094924a Mime-Version: 1.0 Message-ID: <2664e2ef-b965-407c-90fc-77480846a3ad@www.fastmail.com> In-Reply-To: References: Date: Tue, 23 Feb 2021 11:28:03 -0600 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Inline conditional that returns null if falsy From: larry@garfieldtech.com ("Larry Garfield") On Tue, Feb 23, 2021, at 10:49 AM, Albert Casademont wrote: > Another example is when a scalar input needs to be either left null or > converted to a Value Object: > > $color = $data['color'] ? new Color($data['color']) : null; > > This would become; > > $color = $data['color'] ? new Color($data['color']); //the ": null" part is > implicit > > It's actually kinda the inverse of the "?:" operator. > > As Guilliam said, Twig already implements such behaviour, it's quite handy > when dealing with nullable variables, 1) Please don't top post. 2) The advantage of ?: over long-ternary is that the part it lets you omit is of variable size, and is often verbose (nested array elements). That's not the case here, as the omitted portion is a fixed length short constant value (": null"). So the value of the abbreviation is much less. I am also not a fan of null being commonly used, as it is a dangerous value. More often I would not want null if the color were missing but some default color value, which would be represented by something other than null anyway. And "falsy" is, as we've been reminded numerous times, a dangerous and tricky thing. (I just had several PRs against one of my OSS libraries because it relied on falsy, which had all sorts of incorrect failure conditions.) I'd be a -1 here. --Larry Garfield