Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
C0D4681385yI see you found a shitfest if a project. Welcome to the wonderful world of legacy php.
-
@C0D4 oh I did HAHAHA
Every day I complain about this shitfest I remember it's almost over and it's going to pay for a wonderful trip. -
Probably written when empty wasnt a thing
I wouldve guessed this is used to explicitly check for an empty but theres no ===and also no string typehint so hello legacy my old friend -
Danger...
Empty doesn't mean the same as the string comparison.
Empty does a whole lot more...
https://php.net/manual/en/...
Especially null can bite you. -
@ThatPerlDeb yeah, I tried to guess all sorts of things, even your suggestion - but nope, empty() exists since PHP4 (at least).
I decided to run a usage search. Turns out all uses are with array_filter(). But turns out array_filter() ALREADY filters our falsey values! Any surprise on this getting worse as I dig deeper? hahaha -
@IntrusionCM sorry, what?
null == "" is the same as empty("") or empty(null).
Of course empty() is not the same for ALL cases, but PHP type-juggling allows us to do that kind of replacement without much judgment in 99% of the cases... -
@igorsantos07 i said "CAN bite u". Not will bite u in this case. ;)
In ur case "array()" would lead to different results:
@highlight
$vars = [null, "", array()];
foreach($vars as $var)
{
var_dump($var);
var_dump($var != "");
var_dump(!empty($var));
}
NULL bool(false) bool(false)
string(0) "" bool(false) bool(false) array(0) { } bool(true) bool(false) -
@IntrusionCM sidetracking... wouldn't it be easier if DevRant actually had markdown formatting?
I mean... Every dev knows markdown, right? lol
Related Rants
The legacy-PHP-project-to-pay-my-future-trip strikes again.
WHY NOT !empty($var) OMGGGGGGG
rant
redundant code
unmaintained code
legacy code
php
dumb code