Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127045 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 CE5761A00BC for ; Sat, 5 Apr 2025 12:15:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1743855213; bh=1CWsUlE3nGWbU77h+NaKEzfdBrqZc5gJnlOlx+kkKoE=; h=From:Date:Subject:To:From; b=Jsq/S/EbuSfphCcUobx9eXFpovZgDlt2L3sJemFcIO/VAW7w9EK4KvV5YHyCEXxu2 H7veZyvH/A7TAQt/t7S5Y2TPZPhaew0I632zxSMqmiQ4oDvC7KwHYoeJ6yAGsgDkKz oR5g9J1LnZ+KKJbngb5r6bBSCZxpMJUlqNvsbvBYA6M7T7Y6iM/cyc+I71kIvO5/OJ GyYHPFw4fXZpCOG/D60A4EKCg5r0KzQ9SoK69w49vy6viz6fPEZQuFgcZltUuB20Ns 1ddg8nogjOfxaZkb2x+9ODjaImq55DjtaYa4B/ETLUlwjqEGx6ypDBlguWKYagU+Ni ylWGhhVPj9MCg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3DDC518006C for ; Sat, 5 Apr 2025 12:13:32 +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=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 12:13:22 +0000 (UTC) Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-30bf1d48843so24779381fa.2 for ; Sat, 05 Apr 2025 05:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743855345; x=1744460145; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=Veyis/Wj7LPCCJKFpCAW44SZu1y9661mswymGrjwcik=; b=X+2T6EvtHV5rAsnCJ2+iPtz7Yef4K71DlyG8sMhNoVAGQKAgIwtXztYICDGKbfAOMX L1pxmQAnil7nOSzMvW9Ts312+9fabBnkfQq9VoXZGzAP3wpWDjprDIOb8/h7/x8wZcTQ 40trrH03bE0G1HTeIeO2P1MItGGd9lVBcCPrgTpWqn6OTZ2H4A8PHKYUhPZ9LntAzHik TTHinAi+Ec0o9jBoXtomnqb6P6KNonrGmOzIjIeEwkBcM14YXaKjEzB+YOXQ3BdAb9jj LxR/cfM1F1gukelFKsEqav0j9erQd/RKe3Pm3wntnUYa5ZXEB6qr0vVgswG403Smc4To E72A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743855345; x=1744460145; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Veyis/Wj7LPCCJKFpCAW44SZu1y9661mswymGrjwcik=; b=n9eNcW3WtAD5hiAATocoh+P5diahXDdWDdFFrYOn4VJAesXDHzZpTuD896MEWtM1R3 BjXOI0dPwDS/O88to0kSZ6HMnvuplyeWSEk3hEE6RV3Ql7Uz93sdzq1VRX89BhE3+mYV 3wRLW/ngPKGbGnYIYG20zJn6mjyy+S9oQO8ZYA70DWSaJa2DoIITkgT7W3FUmKiWmTlj +Mr37ppOujtjTIbIUrhCM9n7CmQtILIoUHNjJu6cANtKs8eqoWVCPzun2KD8McD9AWRm 32fHQA6GZaznJMhvxojhVmAHge1w3hNdQ6ykphhd/gRk4Ol4ICKhy+2Rkjx4uXulRsqi RI6A== X-Gm-Message-State: AOJu0YydCsoZtesAr6P0Zj7jWKhBQx/L9nn/LJf3B8OWpGtQldGUmo9W HjJBAXDoKTWDb30f2UMiLZeuHUJhxUpNJVS/HLh4qS8HPaJCamQ9BW59aR+QPq+HY4fZFWIcSK5 e6HXBBnnUDvElC0Xp80TgnKz6wHqecj5GyGQ= X-Gm-Gg: ASbGncvEhrR3jpKRCBsc1oBpAkGyDPb2BEQR11eyvGBlrigf249gMo2e/BQM4o75ZsF FwhcfoTiBavKerRdpMrq4BAYaOHR9qAsMROxeKqmJzR0bGr37zdIWpAb/LcmoiQ9YG6uCy6UvRS aIBE/tzg7PkhTAflYQpKdOgy3qAJpMyNez9GCPsrPdUJiaNEnu6iIaDtCGoxk4 X-Google-Smtp-Source: AGHT+IEppfWIlhDWO5vr8NXdJYin/a1zeTP/W7C+epzKBqrYiNTtk8POy/7HYc8BNeFdcFYCghZhz+oTmWr4rgVbu5o= X-Received: by 2002:a05:651c:30cb:b0:30b:cd41:89c7 with SMTP id 38308e7fff4ca-30f0bf4fcbbmr19339011fa.22.1743855344847; Sat, 05 Apr 2025 05:15:44 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Sat, 5 Apr 2025 09:15:33 -0300 X-Gm-Features: ATxdqUEpQty8IvwtwQ1YHQ6Lv6G2xVF7Z2yKCITUq4WaVHWJ8me1O36z1WG4N3M Message-ID: Subject: [PHP-DEV] RFC: blank() Function as a Complement to empty() To: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000005e94de063206f658" From: kayckmatias04@gmail.com (Kayck Matias) --0000000000005e94de063206f658 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable *INTRODUCTION* This RFC proposes the addition of a new global function blank() to PHP=E2= =80=99s core, intended to provide a more intuitive and context-sensitive way of checking for "blank" values. This function is *not a replacement* for empty(), but a *complementary tool *to help developers more accurately evaluate user input, query parameters, and form values =E2=80=94 particular= ly in situations where empty() may behave in unintuitive ways. *MOTIVATION*The motivation for this RFC arose from a real-world issue I encountered at work involving query string filtering =E2=80=94 specifically= when using the string "0" as a filter value. Because empty("0") evaluates to tru= e, the logic skipped this valid input, causing incorrect behavior in the application. This highlighted a gap in PHP=E2=80=99s current toolset for ha= ndling =E2=80=9Cblank=E2=80=9D values in a more semantic and intention-aligned way= . *PROPOSAL* The proposed blank() function will behave similarly to empty(), but with semantics better suited for filtering, validation, and user input. Its primary goals are: - To treat whitespace-only strings as blank (e.g., " "). - To treat "0" (string zero) and 0 (int zero) as *not blank*, unlike empty(). - To support clearer, intention-driven logic when working with dynamic input, especially in query strings and HTTP forms. Function Signature function blank(mixed $value): bool; Logic (PHP version) function blank(mixed $value): bool { if ( false =3D=3D=3D $value || (empty($value) && '0' !=3D $value) || (\is_string($value) && '' =3D=3D=3D \trim($value)) ) { return true; } return false; } Examples echo blank(null); // true echo blank(false); // true echo blank(""); // true echo blank(" "); // true echo blank([]); // true echo blank(0); // false echo blank("0"); // false echo blank("test"); // false echo blank([0]); // false *BACKWARDS INCOMPATIBLE CHANGES* This feature is fully backward-compatible. It does not alter existing behavior of any function or construct, nor does it redefine empty(). It introduces a new global function and does not break any existing code. *RFC IMPACT* - *CLI & Web usage*: This function will be available globally, in both CLI and Web SAPI contexts. - *Core behavior*: The function is small, simple, and does not interfere with any existing language behavior or constructs. - *php.ini*: No changes required. - *New constants*: None introduced. This function is expected to improve *code clarity and correctness* in real-world applications, without burdening the language with complexity. *COMMUNITY FEEDBACK*Multiple developers have voiced concerns regarding empty() in real-world scenarios. A key example is PHP Issue #9845 on GitHub, where it's reported that: "empty("0") returns true when it should return false." This discussion highlights a recurring problem: developers often expect '0' to be treated as a valid, non-empty input (e.g., in filtering query strings), but empty() evaluates it as false. This leads to conditional logic silently skipping valid inputs. The blank() function is designed to directly address this gap, offering a more semantic and human-friendly approach to "blankness" that aligns better with what developers actually expect in these cases. *NEXT STEPS*This is my first RFC proposal, If there are any issues with the approach, naming, scope, or anything I may have overlooked, I=E2=80=99d gre= atly appreciate your guidance. If there=E2=80=99s interest in moving forward, I will prepare the full RFC documentation on the wiki along with an implementation patch and appropriate tests. *Thanks in advance for your time and input!* Best Regards, Kayck Matias =E2=98=95 --0000000000005e94de063206f658 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
INTRODUCTION
This R= FC proposes the addition of a new global function=C2=A0blank()= =C2=A0to PHP=E2=80=99s core, intended to provide a more intuitive and conte= xt-sensitive way of checking for "blank" values. This function is= =C2=A0not a replacement=C2=A0for=C2=A0empty()= , but a=C2=A0complementary tool=C2=A0to help developers more accurat= ely evaluate user input, query parameters, and form values =E2=80=94 partic= ularly in situations where=C2=A0empty()=C2=A0may behave in uni= ntuitive ways.


MOTIVATION
The motivation for this RFC arose from a real-world issue I encountered at= work involving query string filtering =E2=80=94 specifically when using th= e string=C2=A0"0"=C2=A0as a filter value. Because=C2= =A0empty("0")=C2=A0evaluates to=C2=A0true, the logic skipped this valid input, causing incorrect behavior in the a= pplication. This highlighted a gap in PHP=E2=80=99s current toolset for han= dling =E2=80=9Cblank=E2=80=9D values in a more semantic and intention-align= ed way.

PROPOSAL
<= div>The proposed=C2=A0blank()=C2=A0function will behave simila= rly to=C2=A0empty(), but with semantics better suited for filt= ering, validation, and user input. Its primary goals are:

    To treat whitespace-only strings as blank (e= .g.,=C2=A0" ").

  • To treat=C2=A0"0"=C2=A0(string zero) and=C2=A0= 0=C2=A0(int zero) as=C2=A0not blank, unlike= =C2=A0empty().

  • To su= pport clearer, intention-driven logic when working with dynamic input, espe= cially in query strings and HTTP forms.

Function Signature

function blank= (mixed $value): boo= l;

Logic (PHP version)
function blank(mixed $value): bool
{
if<= /span> (
false =3D=3D= =3D $value ||
(e= mpty($value) && '0' !=3D $value) ||
= (\is_string($value) && '' =3D= =3D=3D \trim($value))<= /font>
) {
return true;
= }

return false;
}
Examples=
echo=C2=A0blank(null);=C2=A0// true
echo=C2=A0blank(<= span style=3D"color:rgb(189,147,249)">false);=C2=A0// true
echo=C2=A0blank("");=C2=A0// true
echo=C2=A0blank("=C2=A0");=C2=A0// true
echo=C2=A0blank([]);=C2=A0// true

echo=C2=A0blank<= /span>(0);=C2=A0// false
echo=C2=A0bla= nk("0= ");=C2=A0// false<= /div>
echo=C2=A0blank("test");=C2=A0// false
echo=C2=A0blank(= [0]);=C2=A0// false

<= /div>
BACKWARDS INCOMPATIBLE CHANGES
This feature= is fully backward-compatible. It does not alter existing behavior of any f= unction or construct, nor does it redefine=C2=A0empty(). It in= troduces a new global function and does not break any existing code.
<= /div>


RFC IMPACT

    CLI & Web usage: This f= unction will be available globally, in both CLI and Web SAPI contexts.

    <= /li>
  • Core behavior: The f= unction is small, simple, and does not interfere with any existing language= behavior or constructs.

  • = php.ini: No changes required.

  • New constants: None introduced.

This= function is expected to improve=C2=A0code clarity and correctness<= /strong>=C2=A0in real-world applications, without burdening the language wi= th complexity.


COMMUNITY FEEDBACK
Multiple devel= opers have voiced concerns regarding empty() in real-world scenarios. A key= example is PHP Issue=C2=A0#9845=C2=A0on GitHub, where it's reported = that:

"empty("0") returns true when it should return f= alse."

This discussion highlights a recurring problem: developer= s often expect '0' to be treated as a valid, non-empty input (e.g.,= in filtering query strings), but empty() evaluates it as false. This leads= to conditional logic silently skipping valid inputs.

The blank()= function is designed to directly address this gap, offering a more semanti= c and human-friendly approach to "blankness" that aligns better w= ith what developers actually expect in these cases.


NEX= T STEPS
This is my first RFC proposal,=C2=A0If there are any issues = with the approach, naming, scope, or anything I may have overlooked, I=E2= =80=99d greatly appreciate your guidance.

If there=E2=80=99s interest= in moving forward, I will prepare the full RFC documentation on the wiki a= long with an implementation patch and appropriate tests.

Th= anks in advance for your time and input!


<= /h2>

= Best Regards,
Kayck Matias=C2=A0=E2=98=95
=
--0000000000005e94de063206f658--