Differences in session variable declaration - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Differences in session variable declaration (/showthread.php?tid=71679) Pages:
1
2
|
Differences in session variable declaration - n2fole00 - 09-12-2018 Hi, I have the following hook PHP Code: class LanguageLoader With the line PHP Code: $site_lang = $_SESSION['site_lang']; PHP Code: A PHP Error was encountered but replacing it with PHP Code: $site_lang = $ci->session->site_lang; RE: Differences in session variable declaration - InsiteFX - 09-12-2018 When using: PHP Code: $CI =& get_instance(); Your getting CodeIgniter's Controller Class. Are you loading the Session library in the Controller or are you Autoloading it? RE: Differences in session variable declaration - php_rocs - 09-12-2018 @n2fole00 It could be what value is returned between the two. You could do a var_dump on both values and see what is returned that should give you the answer that you seek. RE: Differences in session variable declaration - n2fole00 - 09-12-2018 (09-12-2018, 02:20 PM)InsiteFX Wrote: When using: I'm autoloading it. RE: Differences in session variable declaration - n2fole00 - 09-12-2018 (09-12-2018, 02:22 PM)php_rocs Wrote: @n2fole00 They both return the same thing. The error occurs when the value is NULL. RE: Differences in session variable declaration - InsiteFX - 09-12-2018 Then use isset method on it to see if it contains a value or not. RE: Differences in session variable declaration - php_rocs - 09-13-2018 @n2fole00, They both are null but one causes an errors and the other doesn't? That can't be right. There is a difference. That is the only reason why one would work and the other not work. InsiteFX made a excellent suggestion as well. RE: Differences in session variable declaration - n2fole00 - 09-13-2018 (09-13-2018, 07:51 AM)php_rocs Wrote: @n2fole00, This is what I was thinking, but what could be the difference? var_dump should give me the output isset would test for. RE: Differences in session variable declaration - php_rocs - 09-13-2018 @n2fole00, What was the exact var_dump for each variable? RE: Differences in session variable declaration - n2fole00 - 09-13-2018 (09-13-2018, 02:08 PM)php_rocs Wrote: @n2fole00, PHP Code: $site_lang2 = $_SESSION['site_lang']; Code: site_lang: NULL site_lang2: NULL isset: bool(false) |