RE: [PHP] Undefined index?

From: Date: Wed, 11 Jul 2001 15:03:26 +0000
Subject: RE: [PHP] Undefined index?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-57400@lists.php.net to get a copy of this message
If one has : $arr = array('a','b','c'); And calls upon the following : $arr[b] (as opposed to $arr['b']) Then the following will result : Warning: Use of undefined constant b - assumed 'b' in ./tmp.php on line 13 Warning: Undefined index: b in ./tmp.php on line 13 Always use quotes around the keys/indexes within associative arrays otherwise the constant is looked for first and unexpected results are possible. Now if we have (which you most likely did) : $arr['d'] Then we get the following as index 'd' does not exist within the array : Warning: Undefined index: d in ./tmp.php on line 13 A similar error is created when doing this : echo $iamnotset; if ($iamnotset) { Which results in : Warning: Undefined variable: iamnotset in ./tmp.php on line 11 Using something similar to isset() helps combat that : if (isset($iamnotset)) { All of the above errors (Notices) are of the E_NOTICE type. If E_NOTICE is turned on within the error_reporting setting within php.ini (or via a call to the error_reporting() function or ...), then you'll see it otherwise you will not. I'm not sure why Notices say "Warning: ..." but they do :-) Typically one turns errors up during development, and down during production use. And, it's not uncommon to see this question come about within various support forums/lists for various PHP applications. Regards, Philip > > -----Original Message----- > > From: Ivo Stoykov [mailto:ivostoykov@hotmail.com] > > Sent: 11 iulie 2001 17:21 > > To: php-general@lists.php.net > > Subject: [PHP] Undefined index? > > > > > > Hi everybody > > > > Does anybody knows what means "Undefined index" error? I > > couldn't find it in > > docs neither in php online doc site. > > > > Thank you > > > > Ivo > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: > > php-list-admin@lists.php.net > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#57400) next »