I am working on a `UserSession` service, the code is below.

My question is, is there any need to do an `isset` test within the `get_id` method or should it be the responsibility of the calling code (in my case the controller) to ensure a session is active?

If the session isn't set, a failure would result in a logout, but I can't help but think that checking for the validity of a user session shouldn't be done in this service, as the use of this service requires a valid user session anyway.

I end up having to do this in every getter.

```
<?php

namespace \App\Services;

class UserSession {

    private $session;

    public function __construct()
    {
        $this->session = (object) $_SESSION;
    }

    public function get_id()
    {
        if(!isset($this->session->user->id))
            return false;

        return $this->session->user->id;
    }
}

```

Any advice?

I'm thinking maybe a method `is_valid()` that returns `true` or `false` is maybe needed. That way the use of the session can be checked prior to calling any of the getters.