Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113240 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14155 invoked from network); 23 Feb 2021 19:17:19 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Feb 2021 19:17:19 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ED3BA1804D1 for ; Tue, 23 Feb 2021 11:05:52 -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.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, 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-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 11:05:52 -0800 (PST) Received: by mail-wr1-f49.google.com with SMTP id l12so23672549wry.2 for ; Tue, 23 Feb 2021 11:05:52 -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=MaT5V9Cm03KyvgkK30NdOTQLLJKRoFpcAD43/Sp2Xro=; b=SC2Urh0scG5n+CqMIfvnb2aFIZbDiyqFIMYZaLD/X9QryeK/AhLZ17wwP1HRH4rIIw WGMG8gx/Pl0adXb0KA8yA/YW8lnpvUb0+xlv0e+x+CkByvgx0XLqL1AtNkoNjRSE4Kl9 saNhFNUJLyLz8Y/uWMTag5TFZoE+eZoYqW5vorj7wV/X7JedLeRECV3f4EkqbsQy5H6J fvqxJSeSHtvPVxKl75O0rOgIyZqpExxEKN7yfERNAuPyhHkWbJdxxrJIteH/ae8Xx+90 cylo4St4+n+CkQjLoEGtY7Emhs4E88Y5Ow7JPmkia/qNchfXNbU2mWvOX3ind/Pm33ms +vJA== 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=MaT5V9Cm03KyvgkK30NdOTQLLJKRoFpcAD43/Sp2Xro=; b=RH37k9w+yRr6N7oVHkIha8AzGRKtF6D6StqyESvyxxk6xaSbeIMtO4vpjZ+kgLgZ8Y u/yeBah91K1HFiPPHjBbdtzmlmeJ3S7J6l25JlZJfwmSK9M8QF6f+FpH8hZaC+wocFIa IOMVT7TKG5PwzraCzXBOdVfCMX3uQaCCjRY/UNGtjYBCe822GMIIS2Cd2jEYcrDnaaJp gkLhXACFhaD0unDvWY/O27roZQO5sDNKRHRAIeyVempBSW8aa3/vo0Jw4dRrR8iEdjNM 1iCHxmUHndwIjKGH4Ut+ey3YKxKo1G072N7mmuYhCk01suYot68OMGe5rzlBTvz1m57C ZoRg== X-Gm-Message-State: AOAM530gSctfrkF737ep0csAIK+2UF4mqW9Kgzf1GlBhgmZnTjN/J9p3 MK9mLmH8qARGiX1oEGVz9f6AG49uX+c= X-Google-Smtp-Source: ABdhPJwkRzFF6Ha49442PdLZbc4Sgg3W5tR7+tvPqPjENLtI6vJoofeNIfdEBBLVmziN01mQUcnKbQ== X-Received: by 2002:a5d:6089:: with SMTP id w9mr27844163wrt.412.1614107147822; Tue, 23 Feb 2021 11:05:47 -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 f17sm32837338wrx.57.2021.02.23.11.05.47 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Feb 2021 11:05:47 -0800 (PST) To: internals@lists.php.net References: <2664e2ef-b965-407c-90fc-77480846a3ad@www.fastmail.com> Message-ID: <84020328-b623-bca1-0c9c-0f7195e08d23@gmail.com> Date: Tue, 23 Feb 2021 19:05:47 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Subject: Re: [PHP-DEV] Inline conditional that returns null if falsy From: rowan.collins@gmail.com (Rowan Tommins) On 23/02/2021 18:41, Albert Casademont wrote: > Sure, it's not a big deal having to write the ": null" but it doesn't add > any value On the contrary, it adds an important piece of information: that the default value is "null", rather than "false", or "0", or "new EmptyValue()". For instance, it doesn't seem at all obvious to me that this code should produce a null: $items = []; $itemCount = $items ? count($items); I might be more convinced that "null" is the "natural" value if the left-hand operand was only checked against null, not "falsiness": in that case, you can read it as "if it's null, leave it alone". I'd still be inclined towards "too specific to use up more syntax", though. > A better example would creating UUID VO's from string|null > input, there's little room for a default here. I'm not quite sure what process you're describing, but any of the following seem equally reasonable: $nullableUuid = is_null($input) ? UUID::for($input) : null; $maybeNilUuid = is_null($input) ? UUID::for($input) : UUID:nilValue(); $definitelyUuid = is_null($input) ? UUID::for($input) : UUID:random(); Syntax for skipping the is_null/isset on the left would be higher up my wish list than syntax for skipping the :null on the right. Regards, -- Rowan Tommins [IMSoP]