Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113256 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 86468 invoked from network); 25 Feb 2021 09:06:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Feb 2021 09:06:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2C4751804B3 for ; Thu, 25 Feb 2021 00:55:12 -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.1 required=5.0 tests=BAYES_00,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-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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, 25 Feb 2021 00:55:11 -0800 (PST) Received: by mail-wm1-f48.google.com with SMTP id x16so3963389wmk.3 for ; Thu, 25 Feb 2021 00:55:11 -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=7c5F+T3LkC7W5eHYuE/Zt1TmcK7pDhVZnXoOG42CccM=; b=sUwX1gSIhlaTWx4MTowyGIdqTJ7oAqp6dGrMNEf/SiHI7xYiRfTaYvMb8cf1GDHWgb ABQNUPJlNZBDSIxRB0EATqnSLclulfPjQr6f1WRPnxMzjrvcPYef4w7cHhfnGOe7PTFk n87yzrvat8WQHLMhMnk/S1HjD8hybtQkPyh8IESNe47yVmNR7UjmBbw/kT63oxfh4NqI DPnfYzKRqOxLnkGnQSx5unuXi6Ue8m68u6Dzm1CTameGIm37vmDP6U1mHzMOhi8ZjQPt au2OcfFhWxrLOELaOkEaocmSGxhHj0Qrds1Sq/niBekIV1LENRlAadknxGPlkBh1B0YF Wlxw== 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=7c5F+T3LkC7W5eHYuE/Zt1TmcK7pDhVZnXoOG42CccM=; b=muwpN2kc5c2iZQtBlqnX0iffG4um+s3aEFi+GK36KhOCZm4H6rw7aiIwWDhwMF2Jq0 9o55fg/CoI8t3EKz2XkwFQvgOVVNeXbLwt9de9CSk5FJTcbnuL1CH8vs5orhzu3nVb5G IZqGBCrad0eKDBzwUmWbZeH0ZP/jtEUtDLlOBoThacxwPFF3VsqnCcFMJ1u+LOKnYDqG m89pX0XgnPREDT5RTZTu1rUh930iBYXAAJ24xpsjtQ1eQeiu9Z3gMhBWfIhcQDPwCgPN x3kL+0rIU5QutrzzpWs2zagzqLXYgEUIl98+a/c7Cey8miy27efqw8U8Q6ZCOdbhmGv2 I/OQ== X-Gm-Message-State: AOAM533KjszpkqJ7TQtRyEJK6TU7A8QnrF2/viiSuRqMqoAXOua+3T7L szE5PzaRCp2HfTD35gE6uujgj8Y7xeA= X-Google-Smtp-Source: ABdhPJz3BcPrvHGzpzuRHwK7kX6pBv5Aiw85khAB4ESR3sG5nPbYTG46VPYsxtQFnVjZQsbtUB572g== X-Received: by 2002:a1c:e402:: with SMTP id b2mr2146778wmh.103.1614243309384; Thu, 25 Feb 2021 00:55:09 -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 f2sm4053362wrq.34.2021.02.25.00.55.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Feb 2021 00:55:08 -0800 (PST) To: internals@lists.php.net References: <2664e2ef-b965-407c-90fc-77480846a3ad@www.fastmail.com> <84020328-b623-bca1-0c9c-0f7195e08d23@gmail.com> <8CD7D960-51FA-45FE-B88F-2A18BA768DA4@newclarity.net> Message-ID: Date: Thu, 25 Feb 2021 08:55:07 +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: <8CD7D960-51FA-45FE-B88F-2A18BA768DA4@newclarity.net> 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 24/02/2021 04:26, Mike Schinkel wrote: > Repeating code similar to that from the message sent by David Rodrigues you can see that eliminating the ": null" is less noisy: > >
...
>
...
That's an interesting use case. Of course, the logical default there is actually '' (empty string) rather than null, since "echo null;" doesn't actually make much sense, but null works under current type juggling rules. Then again, perhaps this is a good example of why PHP *isn't* the best choice any more if you want a templating language. Twig, for instance, has exactly this facility [https://twig.symfony.com/doc/3.x/templates.html#other-operators]: {{ foo ? 'yes' : 'no' }} {{ foo ?: 'no' }}is the same as {{ foo ? foo : 'no' }} {{ foo ? 'yes' }}is the same as {{ foo ? 'yes' : '' }} If we wanted to close the gap between Twig and plain PHP for templating, this might be somewhere on the list, but after more significant features like automatic escaping, filter / pipe syntax, etc. Regards, -- Rowan Tommins [IMSoP]