Which Is Better To Store Data In Session In Yii? Array Or Json

I’m building a shopping cart,and have to store the product list that user has chosen before in SESSION by using Yii::app()->user->setState() . I wonder which kind of data is better in this situation ?

Storing in JSON: by this way, I have to json_encode and json_decode each the set and get.


Storing in array

My question is :

Thinking about performance, which is better in Yii ?

Whole session gets serialized on request end and deserialized at the beginning of next request, so adding other form of serialization just creates overhead.

And it’s better to interact with the session through the session component:




$products = Yii::app()->session['products'];

$products[] = $newProduct;

Yii::app()->session['products'] = $products;