*INTRODUCTION*
This RFC proposes the addition of a new global function blank() to PHP’s
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 — particularly 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 — specifically when
using the string "0" as a filter value. Because empty("0") evaluates to true,
the logic skipped this valid input, causing incorrect behavior in the
application. This highlighted a gap in PHP’s current toolset for handling
“blank” 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 === $value ||
        (empty($value) && '0' != $value) ||
        (\is_string($value) && '' === \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
<https://github.com/php/php-src/issues/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’d greatly
appreciate your guidance.

If there’s 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 ☕

Reply via email to