Basically my basket class has a property $this->items that the session var $_SESSION['items'] is loaded into.
After an item is added to the property, $this->items needs to be loaded back into $_SESSION['items']. Should I technically be doing this on the view or within the class?
Currently:
View(session in) -> class.basket(items set) -> view(Item added) -> class.basket(updates items) -> class.basket(returns items) -> view(returned var loaded into session var)
But I'm considering loading the SESSION into the items property on the constructor then load the items property back into the session on the destructor?
example:
<?php
session_start();
class basket
{
private $items;
function __construct()
{
$this->items = $_SESSION['items'];
}
function dothis()
{
//whatever processing
}
function __destruct()
{
$_SESSION['items'] = $this->items;
}
}
$test = new basket();
$test->dothis();
?>
Should i keep sessions separate from the classes or would this be fine?