I'm trying to update a value in session-Array, but it doesn't work. Initial set:
$bag = new SessionBag('p-' . $productId);
$bag->person = ['name' => 'john', 'age' => 25];
Then update:
$bag->person['age'] = 30;
After that the age is still 25 (checked in a xdebug-session).
If you enable warnings/notices on your web server, you will see something like "Notice: Indirect modification of overloaded property".
How to accomplish what you want?
$bag = new \Phalcon\Session\Bag('testest');
$bag->person = ['name' => 'john', 'age' => 25];
// $bag->person['age'] = 30; // Triggers Notice and will not work
$temp = $bag->person;
$temp['age'] = 44;
$bag->person = $temp;
print_r($bag);
[person] => Array ( [name] => john [age] => 44 )
If you are interested why this happens, you can read few explanations here PHP - Indirect modification of overloaded property