Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113164 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 38491 invoked from network); 13 Feb 2021 03:25:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Feb 2021 03:25:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7C3431804D1 for ; Fri, 12 Feb 2021 19:11:39 -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,HTML_MESSAGE, 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-il1-f177.google.com (mail-il1-f177.google.com [209.85.166.177]) (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 19:11:38 -0800 (PST) Received: by mail-il1-f177.google.com with SMTP id a16so1026160ilq.5 for ; Fri, 12 Feb 2021 19:11:38 -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=ndXgGlvXr7WLB3M5Ds83fzZzWHTJgiiK+uQu7OxkoBQ=; b=OVRc7f25sHr6usRZK3sDIjv4PKDg1uNJR9P/V6NE4EDyepXosqHca4OyjyvjDnpW/V MOuBoIPxH6Buc+nWtDkgYevDsNuUZeFWBpEpkbV+5bAPRGZBxHxkA+AxGBS+emZG4wC4 Lo4taTu7J2EJ64BCncfJUx1pCwiaLnnCDK8z74tt8QQINDXrpBWXjVUvX6yFLfedz6Hc tMCblV7+C06gxJMHgzxKLje75ACqAu5OdCTRsc0ag/EldxrlQNC80HsdqYOgScbIKqEa 4fUaV910I0l3/LanweddSzmxO0+7cKkCyGALYRrAYeujNTjK0uYilJmdlypeFxWbFQ2k i3Uw== 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=ndXgGlvXr7WLB3M5Ds83fzZzWHTJgiiK+uQu7OxkoBQ=; b=RkGIskB3+iYQXetazBWKR8vHrbZ3rXx4UNogSiSHf2p7dIRqAFAxrihA85q32P4JbU ESP9/DwiKNwubvFpsUU0zsO2X3eh2C0V3sHRnNhLGivWQrAKg+c+XH/E2JljMJi85ifd RU/9Rcn8Db1lsjZKNFHUXWDf6hnWThR4TktwzUj/kKCYYwtW4LmsgcSnh7pTJgb4sAtd FNywuVSLBApXZ4H6fceC/VgeGo7huQoij/7T5G/mVbLxQ6D5EG/QVnQvnjxe617pMS9U 4ilQMuLe/amWajoYInGY5/SMzpD3Z4x9Sz5wHB9wzKFRlaBrOiQfmEej3a2HqyOcU1Xq rqRg== X-Gm-Message-State: AOAM531iDBcRogW9TwZftMMcCnQeEVS6DtfKKNH1drFEKRa9wH+EcxAG 2zrJcVJ2oSFV76uqiTman52XO/eZ91V6GHbSEAE= X-Google-Smtp-Source: ABdhPJw2DlQzDeKZ2yffCQZY6Ssoa9P/ulQGTrGdL+D+xy9W6u+uTmH3KIafLS7JL9addhnsC+rj8mq3d0sWgaQLgu0= X-Received: by 2002:a92:3f06:: with SMTP id m6mr4673978ila.283.1613185897973; Fri, 12 Feb 2021 19:11:37 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 13 Feb 2021 04:11:26 +0100 Message-ID: To: David Rodrigues Cc: PHP Internals Content-Type: multipart/alternative; boundary="00000000000067cbcb05bb2f1ccd" Subject: Re: [PHP-DEV] Inline conditional that returns null if falsy From: ocramius@gmail.com (Marco Pivetta) --00000000000067cbcb05bb2f1ccd Content-Type: text/plain; charset="UTF-8" Hey David, On Fri, Feb 12, 2021, 20:24 David Rodrigues wrote: > 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; > Even upfront, this looks like a quite bad idea: either you have an empty collection, or you have a collection with elements in it, but `null` is a very different concept that isn't homogeneous with the resulting type. I've updated multiple projects in the past where `array|null` was used as return type for a collection-alike endpoint, removing `null` and replacing it with an empty iterable instead. > --00000000000067cbcb05bb2f1ccd--