Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127052 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 297D21A00BC for ; Sat, 5 Apr 2025 19:02:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1743879608; bh=ibO7K8V2fqRCI04rYekPrXFOoQ9vyAi2vWJ80dtofv8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=i2tqUX/h+VLb2CDc+bYWi2u1S1ti4VTB+87M0ikhb+g+kdSaUv+osMnLcjqEnJULt YXukoOgSQitXFEghLqWWyohhpQfLXtMaB0kHmGIwOpr0+OehPTiF5k4vh7SkKJ6v76 UsGcjYNw7zByJt9CgfUaQ7eUAIXuQlK1Tta2mZmKaWv+9HQ8y0oNtsuBrk2vPTv9KP wmpkZzpIo/62h4YxeIC/kVWbtAkA+SLWj9on2os04vjwLY4Gs/r7Ed8Bq8RrJXXkL9 3pNvzFzfLceDdn55Nzhhk1sNayYmFqzt0FQlHOEDxWC/4uYuaBTvvluGW6bHEv3jsK fJtJmCeUl2dVQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7D783180390 for ; Sat, 5 Apr 2025 19:00:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,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=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 5 Apr 2025 19:00:07 +0000 (UTC) Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-ac2bdea5a38so500152866b.0 for ; Sat, 05 Apr 2025 12:02:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743879751; x=1744484551; 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=fqcJkVPcOrvYXVUMFk7hRoBWDZegY1j0U+CraCx5O1Q=; b=LK1sJOOeTPh9qVOJuDJejz07YmJnUYpKl495zEn9FSk+nds9a1qL5KkHCuqBGtkl6N HFft97zmuzYWRAd2FCmmIN1Fz7d84fFjxMXnyNeW/ufo7wNXUHyeSjwXd/XXf8Rkb377 iZhRLvwtmq5KRnEEl5/in5ib6h99PjKovDqqxesfJ3+IKJoii/Pp0HKi1rUil/4C2dVW m/mQsdJX7dry4p1KHHur+soh5Dl9B7DrkwulojHhF/QRqEoXDg8mabEEVZNKjRD9nxSg kU9w2sSzkUEPlpSEnpNHCmr2Kp4XluSPB+LPSpSnEVhoaV+ovNstefanP+Bwcb+LdiPo IqgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743879751; x=1744484551; 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=fqcJkVPcOrvYXVUMFk7hRoBWDZegY1j0U+CraCx5O1Q=; b=NYRsjGgwin9g9UrsQzZqwmbxdN6GredqaPhmFnhLWxPiD9YPfWnHQO1t5eXdQynXoH euzI4mT6Fz9c4nSnzf1vbG667SMuUDY/di0xDSRg17WCHgm+4V807Lr22CCxMxkYEAss EXwlI6xom/JV2+AsoZMRnWyFzqc1N35sr/kZvTCH3viNGt1Ho5J0ftvz5xjXDnCuFn6R bJMorzHM7xPeY0/wruGnfDtFcziPATZxP31fHYHylCTYlTEEl9JF6g4sZxIxSWdP3Wkc zpZrjh8U06544n5eNrC8WcvDsbcMVi7W0Jz481YSIlqQvoxbUGIY8shlDGnDgkUUYiiN j9SQ== X-Gm-Message-State: AOJu0YwgFbwV/hiG/Rho9W88VnAM0idbnDK0Q0GQ85T+JX1I+NxNoOGU PtNMmKzs/fcdK3bQUEuaNoG7jSF24we17QyAGG6c1tXxIfRGkbI9fwYYmDpqI+lf0OUhRFwU91x w7jevLrv58Nu2v49ssXgmWJwa+SRhJZ3JDII= X-Gm-Gg: ASbGncsVH6deA10ZtM7KDo2U/vdYUHH9yr11ODvKno7NtSJiMSU8Av4Lu4MuojIJM45 P6z+IEPoMQAoSLHiUUV4C/v25UMUZM3bjSBJl3xNBjjOynKi1+WHDU8VrBHqyjgPngcubJuAvhh YkXSo+D1Ct50MxIB7bmR4loZQY4g== X-Google-Smtp-Source: AGHT+IEmH+rPMePIKu74ZBTxUwOezykQs047nUywrFiXTtc1BH1Cx8t7Ys842QqUV891R95ONRzUkeFinQ3BRPrGr9k= X-Received: by 2002:a17:907:2cc2:b0:ac3:898a:f36d with SMTP id a640c23a62f3a-ac7d6d598d8mr606930066b.30.1743879751147; Sat, 05 Apr 2025 12:02:31 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <68e5b45e-1ae1-452b-9b4d-788e11c8cfe1@scriptfusion.com> In-Reply-To: Date: Sat, 5 Apr 2025 22:02:20 +0300 X-Gm-Features: ATxdqUEQDwjlNfTz8TNzKEDU1K258ytJrSMeBm-0GW4zch9xN8mvU1P65eOW8tI Message-ID: Subject: Re: [PHP-DEV] RFC: blank() Function as a Complement to empty() To: Rob Landers Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000192a1406320ca509" From: i.miroslavov@gmail.com (Iliya Miroslavov Iliev) --000000000000192a1406320ca509 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > echo blank(" "); // true This case is not blank `empty` checks if a variable is set and contains something so basically what your blank function does. In this example it contains character 32. If you want to remove the "\0" (null terminator) from the language, that's a different story. On Sat, Apr 5, 2025 at 9:45=E2=80=AFPM Rob Landers wrot= e: > On Sat, Apr 5, 2025, at 20:25, Bilge wrote: > > On 05/04/2025 15:32, Kamil Tekiela wrote: > > > > While it has its uses empty() should be avoided whenever possible. > > > Agree. A better RFC would be to just deprecate `empty()`. > > Cheers, > Bilge > > > empty() has very many uses. Once you understand what it is shorthand for, > it makes a lot of sense to use it how it was meant to be used. For exampl= e: > > empty($var) ?: foo($var); > > which is just shorter than: > > if (isset($var) && $varl !=3D false) { > foo($bool); > } > > Generally, you don't use empty() on strings though, just arrays, in my > style guides anyway. For strings, you use `$string =3D=3D ""` or to be mo= re > proper, maybe > > trim($value ?? '') =3D=3D '' > > ... but these days, trim doesn't accept `null`, so that makes it a bit > more wordy than it really should be. However, it is just a deprecation > notice, so it is easy to ignore. For now. > > =E2=80=94 Rob > --=20 Iliya Miroslavov Iliev i.miroslavov@gmail.com --000000000000192a1406320ca509 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
>=C2=A0echo blank(" "); // true

This c= ase is not blank `empty` checks if a variable is set and contains something= so basically what your blank function does. In this example it contains ch= aracter 32. If you want to remove the "\0" (null terminator) from= the language, that's a different story.

On Sat, A= pr 5, 2025 at 9:45=E2=80=AFPM Rob Landers <rob@bottled.codes> wrote:<= br>
On Sat, Apr 5, 2025, at 20:25, Bilge= wrote:
<= div>On 05/04/2025 15:32, Kamil Tekiela wrote:
>
<= div>> While it has its uses empty() should be avoided whenever possible.=
>
Agree. A better RFC would be to just depr= ecate `empty()`.

Cheers,
Bilge


empty() has very ma= ny uses. Once you understand what it is shorthand for, it makes a lot of se= nse to use it how it was meant to be used. For example:

<= /div>
empty($var) ?: foo($var);

which is j= ust shorter than:

if (isset($var) && $= varl !=3D false) {
=C2=A0 foo($bool);
}

Generally, you don't use empty() on strings thoug= h, just arrays, in my style guides anyway. For strings, you use `$string = =3D=3D ""` or to be more proper, maybe

<= div>trim($value ?? '') =3D=3D ''

... but these days, trim doesn't accept `null`, so that makes it a = bit more wordy than it really should be. However, it is just a deprecation = notice, so it is easy to ignore. For now.

=E2=80=94 Rob
<= /blockquote>


--
Iliya Miroslavov Iliev
--000000000000192a1406320ca509--