Re: New RFC : empty() function

From: Date: Mon, 30 Oct 2023 15:59:28 +0000
Subject: Re: New RFC : empty() function
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-121533@lists.php.net to get a copy of this message
> > This is exactly where the problem lies. Is a string with just whitespace > empty? Why would an ArrayObject with count 0 not be considered to be empty > while an array with count 0 is? "empty" is subjective and therefore not a > reliable function to use. Especially in legacy code I find that people use > empty where they should've been using > count() === 0 and have resulted > in bugs that weren't discovered until months or years later. The variations > of $a === '', count($a) === > 0, ! isset($a), and $a === > null already > check all the scenarios you need, without risking funky bugs due to how the > internal check for "falsy" values works. > trust me, Ive worked on some terrible code bases that do exactly that and have variables redefined or dynamically assigned and you have to really check if it has been assigned a value or not and what value. It might be forgotten by everyone because of how far PHP has come but there is still extensive use of the @ suppressor and the alternative to empty would be if (@$var == "" || @$var == null || @$var == [] || count(@$var) == 0){} empty() is 1 of 3 functions i believe that does not throw an undefined variable warning if you don't @ suppress the variable you are passing in. So if you want to get rid of empty, can we reignite the talks to finally get rid of @

« previous php.internals (#121533) next »