PHP Classes

Notice: Undefined index:

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  Notice: Undefined index:  
Subject:Notice: Undefined index:
Summary:Does this matter re: code execution time?
Author:Ted Rader
Date:2012-12-20 00:39:11
Update:2013-07-22 12:06:28

  1. Notice: Undefined index:   Reply   Report abuse  
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?"

$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?

There is 1 reply in this thread, which is not being displayed.
Browsing this forum thread replies is available only to premium subscribers.

Go to the premium subscriptions page to learn how to become a premium subscriber and have full access to this forum.