Jump to content

Empty doesn't work on session data


LostKobrakai
 Share

Recommended Posts

Hi there,

is this a behavior of "$session->data" a lack of my php knowledge or is this a bug, that empty() returns false?

var_dump($session->successmsg);
var_dump(!empty("Erfolgreich! Ihnen wurde eine Email mit den Download links zugeschickt.;"));
var_dump(!empty($session->successmsg));
$tmp = $session->successmsg;
var_dump(!empty($tmp));

Output: 

string(72) "Erfolgreich! Ihnen wurde eine Email mit den Download links zugeschickt.;"
bool(true)
bool(false)
bool(true)

Greetings,

Benjamin

Link to comment
Share on other sites

$sesion is a wrapper for the native session.

One of the good things is you don't need to do isset($session->data) but just

if($session->data) ...

If it doesn't exists or is empty it will return NULL.

  • Like 1
Link to comment
Share on other sites

WillyC is right :)

Another example that does not work with magic getters:

$arr = array(1,2,3);
$session->arr = $arr;

// Does not work!
echo $session->arr[1];

// To echo out array elements, do this
$arr = $session->arr;
echo $arr[1];
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...