Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121528 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 9768 invoked from network); 30 Oct 2023 15:36:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Oct 2023 15:36:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0E44E180382 for ; Mon, 30 Oct 2023 08:36:06 -0700 (PDT) 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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 30 Oct 2023 08:36:05 -0700 (PDT) Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-9d2d8343dc4so239171866b.0 for ; Mon, 30 Oct 2023 08:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698680164; x=1699284964; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=VykbWa+OL2V3Xr7DRbOdjRvh3yfjO5BsM8W8iSuToKY=; b=mDe+EMcB+mHEuXY+Wr9vzhPIaD6ETPBHtIenA17KurwihIauF5OcczGPBo6L4c5tof l6OzbKGdkp9XW7OrKyW0oczUgQU17JmoHSdFyBh2Qt4v4WVjmdp4mMYkwZ9bbW4/vBBD IyvfJXN5hUix99o39+7rPt1w9X7OmWlTWLYjYMrjZju8YlExzi0I1AxI71Vi0jGWFqTh QAJjKmCPIZf2Md86bK+m475x8vIgEN0WmTgIckC6MSbzBF1eY7pUREtI2aNDCfpzO2pV ri8RsCxS4PuxVepE16KTXLP60F6p4zF5Kv2nmbhAJ3RxLQbPqUAQnQSlaMJIcPwNluMs TWYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698680164; x=1699284964; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VykbWa+OL2V3Xr7DRbOdjRvh3yfjO5BsM8W8iSuToKY=; b=ElF/QntOverF0/34zuHkMCgtNCtnoZFHPzUewtDBEbl2Ac4nyaVR4tz09FRnTtTPZP YKvkDMHtPAaPJbMhlo0gRNr2nyHDrRIEtxBPCp5J0aiiBHWzyvxqRUdevc6oY5fWUrkW F7IYJ656dumm5VPEhfCTRHecbiGJ26+p7hmYLMQ1MQtw7RR5Kw2Wuj/sbWh9Hs6AyyJn XhH1/UuWRlfvLshSjjGgbCDgQo6D9/dLSi1aR/pBst4fxehgLjpq3jSyhTYYyz0c7hV8 rn7s1iyjv0pdIhYEgkP/6TwBAtIm5jcYsn9IzxUKOjfLog6n0qUVDgwJr7vdjY0RKrZr SA6g== X-Gm-Message-State: AOJu0YzQBzcEd65UEzctvaLwJ+di3jaBBYev6FtEYqcPYQMXWgJ6k3nu G7dwPo5LwIP8XzoeI+hBVJX8sVgmYkMKQeT5/r8RAy9R X-Google-Smtp-Source: AGHT+IGVxc6VNOoUegVDjF/N6WowjU9wQEueEIhxA6OvgwFaBGFhdFBuDTqxfUcvgU44uD6n9XcIG7JE4ovSqrAPTMU= X-Received: by 2002:a17:907:9620:b0:9ae:5370:81d5 with SMTP id gb32-20020a170907962000b009ae537081d5mr9428228ejc.41.1698680163870; Mon, 30 Oct 2023 08:36:03 -0700 (PDT) MIME-Version: 1.0 References: <22ad21cc-f6ba-49e9-b1a9-8c73fe173648@gmail.com> In-Reply-To: Date: Mon, 30 Oct 2023 16:35:37 +0100 Message-ID: To: tag Knife Cc: Marcos Marcolin , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000c130c60608f0cbfd" Subject: Re: [PHP-DEV] New RFC : empty() function From: kjarli@gmail.com (Lynn) --000000000000c130c60608f0cbfd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Oct 30, 2023 at 4:21=E2=80=AFPM tag Knife wro= te: > > > > However, according to my example, the variable is defined and has its > > value as 0 or false, and empty() returns true anyway. I confess that > > I've had some problems like this, and we chose not to use empty(), as > > sometimes 0 or false makes sense as a valid value. > > > > That is exactly as the documentation explains it. > empty is to check if a variable is not holding a usable value. > 0, false, true are all valid values and show the variable is not > empty. > > The purpose for empty is to check for undefined variables, empty > arrays or empty strings. > eg. "", [], null or undefined. > This is exactly where the problem lies. Is a string with just whitespace empty? Why would an ArrayObject with count 0 not be considered to be empty while an array with count 0 is? "empty" is subjective and therefore not a reliable function to use. Especially in legacy code I find that people use `empty` where they should've been using `count() =3D=3D=3D 0` and have resu= lted in bugs that weren't discovered until months or years later. The variations of `$a =3D=3D=3D ''`, `count($a) =3D=3D=3D 0`, `! isset($a)`, and `$a =3D= =3D=3D null` already check all the scenarios you need, without risking funky bugs due to how the internal check for "falsy" values works. --000000000000c130c60608f0cbfd--