In my project, I have a wrapper class for $_SESSION
, so session variables can be accessed by $session->var
. I was trying to check if session variables were set or not using isset
:
if (!isset($this->session->idUser)) {
...
}
but isset
is not returning anything. So in my wrapper class I wrote the following function to test what was going on.
public function isItSet($var)
{
die(isset($_SESSION["id"]));
}
this results in an empty page. I tried:
public function isItSet($var)
{
die(is_null(isset($_SESSION["id"])));
}
still an empty page. Then I tried:
public function isItSet($var)
{
die(isset($_SESSION));
}
This returns 1.
Can anyone tell me why trying to check if a session variable is set returns nothing?
var_dump
instead ofdie
orecho
. In PHP a booleanfalse
that is converted to string (in your case for output) will be converted to an empty string.var_dump
will show you the actual value and type. That is just basic PHP, please make yourself comfortable with the language first. – Quito