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

From: Date: Sat, 05 Apr 2025 18:41:23 +0000
Subject: Re: RFC: blank() Function as a Complement to empty()
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-127051@lists.php.net to get a copy of this message
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

« previous php.internals (#127051) next »