Home > Mobile >  Using isset on !$myvar['var']
Using isset on !$myvar['var']

Time:05-26

I'm currently working through a large number of warnings I have logged after my server was updated to PHP 8.

One particular point that has me scratching my head is the following code block

if (!$option['type'] || $option['type'] == "select") {
  $output .= '<b>'.$option['title'].':</b>';
}

I know that I can use isset($option['type']) like this

isset($option['type']) && $option['type'] == "select"

but confused how that would work for

!$option['type']

How can you be checking if isset, but also it being NOT. If it's NOT, then surely it isn't set anyway?

CodePudding user response:

The test for "may not exist or may be falsey" is:

if (empty($option['type']))
  • Related