Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using isset on !$myvar['var']

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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

if (empty($option['type']))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading