Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121531 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14505 invoked from network); 30 Oct 2023 15:46:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Oct 2023 15:46:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3CE7B180539 for ; Mon, 30 Oct 2023 08:46:59 -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=-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_H2,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-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.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:46:58 -0700 (PDT) Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-66d87554434so32945276d6.2 for ; Mon, 30 Oct 2023 08:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698680818; x=1699285618; darn=lists.php.net; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=wLkCMgjGpbKwNdXj1SNylrwEdbppY/RIQtemYXIJuhw=; b=VHEdTKkVt/w44fT2m4P6+fnsRfVKvLTLwuhsc6DRIVdHb9JkA0nIVTtM08uO2oyZG6 OI6j8OcA5SzAAFw1V6gbJ1OXOxa09HcKi2/k85rmYWdz8uyn37Lb4t/5CYUkLVeD1ZiT b89liBzF34wbuML91ToAIL5j7I6Iq2fh9GMbut7U24f4p8VoqKQpC083k7cwufwvzuPG bPGV9cffSmGMgUXFDovROVfXLTa2D/XWNKyOjDba9I4IgIAVbGpganhDuimpP4aEWZWE i0FkxQ9g8VE1Ccxj7SyHkNjIEyImBHtS6bBzgfBsNK+r7dhRcqrqcYX8TRtNNhx3m3fc zZ2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698680818; x=1699285618; h=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=wLkCMgjGpbKwNdXj1SNylrwEdbppY/RIQtemYXIJuhw=; b=N1KeEsrdyyor4IJhV9pipZSA7RN3IvlSWy1jNyZjtYIaK402RONw9d8u76f6ayxwIw KtQD2WoWVRMLJYLbu/W5Bve3duJcqlKTV0qPVSHkUoo5K5ErTLKpPJmT6GZgBrVmSQSB VNKL0PJOjgfk0qV21cAKUiUWigzfL+jvmqIh19dCAo8raz0FLSFgoiJyTMrric3hP7Qy MtefNcfbWlWrCrijhUe+D6vdn9UVIyWClbZFM9nbkjk1du6/PUyrCHHelEqbzqrGZjIc ePaPLeZE8dQPNCfFxPk/s99T5qIjHJYuFIg5CCc5rlNz5P+Z+6yqz6ZkzZ/3VxP6xglw BJIg== X-Gm-Message-State: AOJu0Yyyg/HGIaDMnBerwGOLsjNfh21BGKuinOxITrPD2lrL82PReXhB RYSCK1raNU8ffJ3RG/C1LcLvetSiiEsOw2jEPZwJ8JBx X-Google-Smtp-Source: AGHT+IFk6KSk2hj9gwkUhyzR1QqFxcmYutmUFDNQsX48+5lAePORjXKBCqILtib/k5Jy1/Bn5sIG/8UGWKMgli3vgN8= X-Received: by 2002:a05:6214:c47:b0:64d:254a:63dc with SMTP id r7-20020a0562140c4700b0064d254a63dcmr13965747qvj.19.1698680817989; Mon, 30 Oct 2023 08:46:57 -0700 (PDT) MIME-Version: 1.0 References: <22ad21cc-f6ba-49e9-b1a9-8c73fe173648@gmail.com> In-Reply-To: Date: Mon, 30 Oct 2023 16:46:46 +0100 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000be3a7f0608f0f24d" Subject: Re: [PHP-DEV] New RFC : empty() function From: alessandro.a.rosa@gmail.com (Alessandro Rosa) --000000000000be3a7f0608f0f24d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks everybody for joining this discussion. I appreciated a lot the points you raised, as they are helping me to update and improve my rfc, whose meaning, as I hope, would look clearer than the earlier version. Alessandro Il giorno lun 30 ott 2023 alle ore 16:36 Lynn ha scritto= : > On Mon, Oct 30, 2023 at 4:21=E2=80=AFPM tag Knife w= rote: > > > > > > > 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 empt= y > 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 us= e > `empty` where they should've been using `count() =3D=3D=3D 0` and have re= sulted > in bugs that weren't discovered until months or years later. The variatio= ns > 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 t= he > internal check for "falsy" values works. > --000000000000be3a7f0608f0f24d--