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

From: Date: Sat, 05 Apr 2025 19:02:20 +0000
Subject: Re: RFC: blank() Function as a Complement to empty()
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-127052@lists.php.net to get a copy of this message
> 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 PM Rob Landers <rob@bottled.codes> wrote: > 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 example: > > empty($var) ?: foo($var); > > which is just shorter than: > > if (isset($var) && $varl != false) { > foo($bool); > } > > Generally, you don't use empty() on strings though, just arrays, in my > style guides anyway. For strings, you use $string == > "" or to be more > proper, maybe > > trim($value ?? '') == '' > > ... 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. > > — Rob > -- Iliya Miroslavov Iliev i.miroslavov@gmail.com

« previous php.internals (#127052) next »