Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113245 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 95407 invoked from network); 24 Feb 2021 16:16:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Feb 2021 16:16:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BBC711804F4 for ; Wed, 24 Feb 2021 08:05:42 -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,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (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 ; Wed, 24 Feb 2021 08:05:42 -0800 (PST) Received: by mail-ot1-f44.google.com with SMTP id k13so2579146otn.13 for ; Wed, 24 Feb 2021 08:05:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SFWH+/7uEsouztnLvQlXkK+/cFnxZiCso4SFd+sFh/s=; b=A8Zsn9w6en6Oj41vGu/W4mHAH880rlZ6N1XSCHbo/DR2oZXt2p1HmleSpS1CCQk6s5 btS/DmlCugkBtzJT2Ug+uFH7oD41BGb/5Dv3N8UDkUdl8e6TJoRzJTWyBU0hapRV7k+V Rq1ByBYVfd8p3Ejd9UcHqb0sc0V2Mowd+oWHIGN69QsJOvY9+zxFrcNQdCRw10IDnHuC hnNfUcKddaK47QfZJGjUXE64ooV5wfkrcCmnF+Js483A9E7lJXGAi9p/69MXOV1ByD6y I6pplp8yYfsvkOBhrJ19Yb+FoS/hdDYOVtkoPbDyxYT+Xhe5v/7hCdqvBqYMIwAeVULJ D5QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SFWH+/7uEsouztnLvQlXkK+/cFnxZiCso4SFd+sFh/s=; b=dLsPAQ15RXLR/5DDq1A8gOUgLg0CG28O8dA31qtVH756nz8mqRbxz7zoXxQraDdlEw j9+ZIgu9TdkaABgzkOJA6m/U8DTMMPSMvYYXYsCeYYKEG+IR2yyIlIgKf5c7sgsjBmEL +5xBt3HebTsyXTT9Tay0oS6lpxSBDSxgwSwpTqJHY8eB5BmPaikbSyiqnPkwaG1w5jbh lMvu5UgVkZDhRete//DNgc0JdjLIcCv8p8ZJ322Eb9tInc5oCoUz9YkSWw67VSdgS/nY fNzb+D0cHP5L1QiL1v12ggnIdY5K7QAXpXhB+jR63XPBaSBNt3LebYk12+EdxaJQiT1N i9Sg== X-Gm-Message-State: AOAM5303jMhv9stPOQY4grfMxqltNiiAEELKSld0Yej1r/7P1GeZhyYi CBMJJ4TfSVtSLPpblzeuvvtBV1YgIE1BjfABO8E= X-Google-Smtp-Source: ABdhPJwU12xUDjeuqFXjhjYyvv2efXrdG9+AYWEC0xCbHPh9S8k2zgH3XbpOpWp+g7Oc5A/CpibMyFF+s8+KctfH1Nw= X-Received: by 2002:a9d:7587:: with SMTP id s7mr13953384otk.114.1614182741680; Wed, 24 Feb 2021 08:05:41 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 24 Feb 2021 13:05:29 -0300 Message-ID: To: Michael Morris Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000ebb67605bc1734fd" Subject: Re: [PHP-DEV] Inline conditional that returns null if falsy From: david.proweb@gmail.com (David Rodrigues) --000000000000ebb67605bc1734fd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Em qua., 24 de fev. de 2021 =C3=A0s 12:29, Michael Morris escreveu: > Javascript has this now though support isn't widespread. > > > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operato= rs/Optional_chaining > > The most similar way to do it in PHP would be ?-> > Optional chaining is not the same. My suggestion is similar to: $variable =3D $user->exists ? $user->fullname; // suggestion (will return null if expression is falsy) $variable =3D $user->exists ? $user->fullname : null; // same as Optional chaining is: $variable =3D $user?->exists; // PHP 8 $variable =3D $user && $user->exists ? true : null; // same as --000000000000ebb67605bc1734fd--