Creating array property in SessionSection has no effect
Closed this issue · 1 comments
thorewi commented
Version: 3.1.0
Bug Description
When I create sessionSection and save an array property to it with one element, it does not have any effect.
Steps To Reproduce
$cart = $this->session->getSection('cart');
$cart->items[0] = 0;
echo $cart->items[0];
I get notice Trying to access array offset on value of type null
.
Expected Behavior
To get 0
redeyecz commented
There is a typo in Nette\Http\SessionSection, missing reference in __get
/**
* Gets a variable from this session section.
* @return mixed
*/
public function &__get(string $name)
{
$data = &$this->getData(false); // <=== this line is missing the reference in version v3.1.0
if ($this->warnOnUndefined && !array_key_exists($name, $data ?? [])) {
trigger_error("The variable '$name' does not exist in session section");
}
return $data[$name];
}