CodeIgniter Forums
Undefined index for session data item - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Undefined index for session data item (/showthread.php?tid=47612)



Undefined index for session data item - El Forum - 12-15-2011

[eluser]Unknown[/eluser]
The following bit of code is returning an undefined index error/notice on the first line (discount_rate) but in my understanding, if a userdata entry doesn't exist, then false should be returned. I know that the error is just a notice and that such errors can be hidden, but I don't really see why I am getting the error at all (well, obviously because the entry doesn't exist, but it should be being "handled").

Code:
if(!$this->session->userdata['discount_rate']) {
     $this->session->set_userdata['discount_rate'] = 1;
}

If anyone can suggest a way to test whether a userdata item exists, then please share!! Thanks!