Ted Rader - 2012-12-20 01:13:28
I'm using WordPress, and I get this in a custom plugin I created. I understand why this occurs, my question is "does it matter?"
Example:
$arr = array(
'a' => 'abc',
'b' => 'xyz'
)
if ($arr['c'] == 'whatever') {
// do something
}
Since $arr['c'] doesn't exist, a notice will appear if WordPress's debug is set to true.
Assuming WordPress debug is set to false (and notice will not appear), is it better to use:
if (array_key_exists('c', $arr) && $arr['c'] == 'whatever') {
// do something
}
What are the negatives of NOT checking if the key exists? Which way is recommended?