DEV Community

Discussion on: Using isset() and empty() hurts your code

Collapse
 
tchaflich profile image
Thomas C. Haflich

The main time I find myself using isset() is for medium-to-big nested arrays, because it evaluates to false instead of throwing an exception if one of the more middling keys doesn't exist.

Eliminates a couple bothersome checks for if ($arr['foo'] && $arr['foo']['bar'] && $arr['foo']['bar']['baz']...), since you can just if (isset($arr['foo']['bar']['baz'][...]). It's not necessary, but convenient for working with more complex data structures.

I can't really think of other times I've needed to use it. Mostly strict equality checks and array_key_exists() work without issue.

Collapse
 
vlasales profile image
Vlastimil Pospichal

Deep structures are unwanted in OOP. Maybe you use it for read a configuration, but read and inject a subtree is more explaining.