Question

I'm new to FuelPHP and I'm trying to understand why I get the following error when I try to set two session variables.

One option is to whitelist the session class, but I don't want to do that without the understanding of what's happening.

Session::set('user_id', $user->id);
Session::set('user_name', $user->user_name);

My user object look like this

object(stdClass)#31 (2) {
   ["id"]=> string(2) "19"
   ["user_name"]=> string(18) "John Smith"
}

And this is the error I receive

Object class "Fuel\Core\Session_Cookie" could not be converted to string or sanitized as ArrayAccess.

I also found this from the documentation

This can be any data type, but pay attention when storing objects in the session, as session data is serialized, and there are restrictions to serializing an object.

Was it helpful?

Solution

This happens when you echo out the result of Session::set. My guess is that you've assigned the return value into your viewdata or some other thing that send to the output.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top