CodeIgniter Forums
What is wrong with my usage of isset ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: What is wrong with my usage of isset ? (/thread-62973.html)



What is wrong with my usage of isset ? - cupboy - 09-13-2015

Code:
//if (isset($this->session->account_level))
      $accesslevel = $this->session->account_level;

I don't really need the if statement anyway, but if I use it the result is always false.


RE: What is wrong with my usage of isset ? - Narf - 09-14-2015

Then $this->session->account_level doesn't exist.


RE: What is wrong with my usage of isset ? - cupboy - 09-14-2015

If I comment out the if statement like I did the variable $accesslevel is set to a value, so it must exist. Maybe it's thought of as being a property rather than a variable and perhaps isset doesn't work with properties. Just a guess.


RE: What is wrong with my usage of isset ? - mwhitney - 09-14-2015

If I'm reading PHP's documentation correctly, the Session library would have to define __isset() for this to work properly. It might also be worthwhile to define __unset().

__isset() might look something like this (based on the current definition of __get()):
PHP Code:
public function __isset($key)
{
    if (isset($_SESSION[$key])) 
    {
        return isset($_SESSION[$key]);
    
    elseif ($key === 'session_id'
    {
        return session_id() !== '';
    }

    return FALSE;