Re: RFC: blank() Function as a Complement to empty()

From: Date: Mon, 07 Apr 2025 07:14:38 +0000
Subject: Re: RFC: blank() Function as a Complement to empty()
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message


On 5 April 2025 21:00:15 BST, Rob Landers <[email protected]> wrote:

>I agree with most of these. I do not agree that " " (a space) is blank though. For
>people without last names, this is often their last name to pass validation on forms. 

This is firmly into "space-bar heating" [https://xkcd.com/1172/] territory - failure to
trim whitespace before validation is a common bug, and requiring a name in exactly two boxes is a
common design/localisation failure, but neither justifies the other.

I think a function for "string is zero length or contains only whitespace" would
potentially be useful, but am not convinced it needs to accept any other type, or have the
error-suppression power of isset/empty - adding ??'' inside a function call is not a big
burden for new code.

That said, I just realised there is a ctype_space function, and I've never used it or seen it
used; normally, trim($foo)==='' (or trim($foo??'')==='') seems to be
good enough.

Rowan Tommins
[IMSoP]


Thread (16 messages)

« previous php.internals (#127066) next »