![]() |
Using (@) error suppression on Undefined Variables - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Using (@) error suppression on Undefined Variables (/showthread.php?tid=22448) |
Using (@) error suppression on Undefined Variables - El Forum - 09-10-2009 [eluser]Gwarrior[/eluser] Is the proper way to keep undefined variables in a page from erroring to use the @ operator? For example, on my view: Code: <?php if (@$logged_in == TRUE) { ?> If logged_in is not supplied (which looks at the session userdata and marks the variable as a boolean value in the controller), is it okay to do this? Thanks! Using (@) error suppression on Undefined Variables - El Forum - 09-10-2009 [eluser]bigtony[/eluser] It's VERY bad practice to use undefined variables, and therefore the use of @ should only be needed on rare occassions. If you are using CI sessions then the variable won't be undefined in any case: Code: $logged_in = $this->session->userdata('logged_in'); Using (@) error suppression on Undefined Variables - El Forum - 09-10-2009 [eluser]cahva[/eluser] ..or use: Code: if (isset($logged_in) AND $logged_in == TRUE) Using (@) error suppression on Undefined Variables - El Forum - 09-10-2009 [eluser]Gwarrior[/eluser] Can you reference session data from a view or do you have to pass it down through a variable? Using (@) error suppression on Undefined Variables - El Forum - 09-10-2009 [eluser]bigtony[/eluser] [quote author="Gwarrior" date="1252592242"]Can you reference session data from a view or do you have to pass it down through a variable?[/quote] Yes, you can reference it in a view, something like this: Code: <body> |