Re: Undefined index ???
| From: | Torsten Roehr | Date: | Wed, 09 Jun 2004 20:50:21 +0000 |
| Subject: | Re: Undefined index ??? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-187984@lists.php.net to get a copy of this message | ||
"John Nichel" <john@kegworks.com> wrote in message
news:40C7729B.205@kegworks.com...
> Michael Jonsson wrote:
> > Hi
> >
> > Why do I get an error if the $_SESSION['user_status'] is NULL ???
> >
> >
> > ####Script######
> > session_start();
> > echo $_SESSION['user_status'];
> >
> >
> > #####error######
> > Notice: Undefined index: user_status in
> > /var/www/itmdata/include/include.php on line 13
> >
> >
> >
> > Regards
> > Micke
> >
>
>
> That's not an error. Three ways to solve this...
>
> 1) Turn down your error reporting level.
> 2) Declare your variables before using them
>
> $_SESSION['user_status'] = NULL;
> echo ( $_SESSION['user_status'] );
>
> 3) Code for variables that may not exist
>
> if ( isset ( $_SESSION['user_status'] ) ) {
> echo ( $_SESSION['user_status'] );
> }
>
> Or any combination of the three.
I would not recommend turning down the error reporting level. This might
lead to unexpected behaviour in your application and makes it hard to back
track errors.
Always develop with error reporting set to E_ALL. You may set a lower level
for your production environment and disable the display of errors:
ini_set('display_errors', 0);
Regards, Torsten Roehr