Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113158 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6900 invoked from network); 12 Feb 2021 19:39:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Feb 2021 19:39:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 992131804CF for ; Fri, 12 Feb 2021 11:24:51 -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.6 required=5.0 tests=BAYES_50,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-f49.google.com (mail-ot1-f49.google.com [209.85.210.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 ; Fri, 12 Feb 2021 11:24:48 -0800 (PST) Received: by mail-ot1-f49.google.com with SMTP id 100so236433otg.3 for ; Fri, 12 Feb 2021 11:24:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=KQef0vVPeuT/xPTrQOIvOgjWC/73UCHkvdi+XBhNzkY=; b=d8h7W2lvIl06zqMry98c14zq3BE70Pm7+t26mA8oAfJ5V5FrRFPjJVKRVVhb/Z9dq5 IZzCBwi4AcA1m5MxDELFsoAtv8c+N2PGIerzH+llqUWAkt39DgCP4uqakPS7zUOqxdVM MwzixOwpdoMVP/ybhY2UZ3OyxM0PMLqvrLlW1SU6KQalFJvGDXRYsJy0kwFwhYRlTcIH ZLTu/r8DW3ipUFfxuCdBQyypg6hSfcFB7KRgxepcVUxjC8368xnRU2LTBtkW1/gEQgN+ 5nNJm2lzBA1RizXmcZRR2PJjjYoMLUNOJgT6DbCuCVBSuelXr0phupg1zXbJQBGVT4Tx dJDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=KQef0vVPeuT/xPTrQOIvOgjWC/73UCHkvdi+XBhNzkY=; b=hknAalL4GY7e6aeSizY1V2CpDSOU+E3AL2R8wO96Kf7TPnYOFkxSSmxaTWm8wMB18B yHVIKJ4OSeWBvXGsAjoiftqLKNVAxZAr5ZEnclEnwgKyEFM4jyUm/EKpSAIb0KPv+2ef +h5KkSQwtC6ko7If+/dMP04GZ9Z9E5ccPRc5kLXfVjc1Q5gGivH7fs0Zja6eyL/vvD9Z NSEsP7jLrRBmXjrg5MrV2j1Ju5ZKAyy4zueV3rQKsZSjtKT7b+uiaUo3Npyiwit2hn3s htbXJGlSCAr8v3NihWptuDJAX0tvxyARdQb/S3UtPC0GWbgZlMKpTdQercqFtb4M1Gzj w8wA== X-Gm-Message-State: AOAM533FkNn+m0b4iB4eSU1h8Tb92jpdTvNRwN5lpzHSn9J1xJKjQMNC WrlfuY5QG10GvmQQfSGSTfyfwFtmc3MnjkLuxAxXY9ByMFw= X-Google-Smtp-Source: ABdhPJydcFyIAjBUdx1hTLkybt2XekhtoGXFU70Kk/+er0f+3WBtsc6rhLbtzsNbOOYGraPQpLalzB1JiIpWOQa4Xic= X-Received: by 2002:a9d:578a:: with SMTP id q10mr3424619oth.114.1613157887046; Fri, 12 Feb 2021 11:24:47 -0800 (PST) MIME-Version: 1.0 Date: Fri, 12 Feb 2021 16:24:34 -0300 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="000000000000d2f8d705bb28969f" Subject: Inline conditional that returns null if falsy From: david.proweb@gmail.com (David Rodrigues) --000000000000d2f8d705bb28969f Content-Type: text/plain; charset="UTF-8" Hello! It is just a suggestion to be discussed. A lot of places on my projects I have codes like: $companies = $user->companies->count() ? new Collection($user->companies) : null; So $companies will be null except if the user has companies. My suggestion is create some kind of inline conditional to works like that: $companies = $user->companies->count() => new Collection($user->companies); If the conditional ($user->companies->count()) is true, then will return the value (after =>), else will be null. In my current work project, I have more than 100+ occurrences like that. So some more examples: $userCategory ? $userCategory->getTitle() : null -> It could be optimized to the new nullsafe operator $userCategory?->getTitle() return $languageFirst instanceof LanguageExperience ? $languageFirst->title : null; -> This not, with my suggestion we have: return $languageFirst instanceof LanguageExperience => $languageFirst->title; The => is just a suggestion, other options using existing keywords is: return expr() then output(); return expr(): output(); I do not know if other languages support something like that. Thanks! Atenciosamente, David Rodrigues --000000000000d2f8d705bb28969f--