I have some rhetorical question regarding storing session data in Symfony. We can store session data as variables:
// The First Example
$this->getUser()->setAttribute('hash', $hash);
$this->getUser()->setAttribute('name', $name);
Or as an Array:
// The Second Example
$this->getUser()->setAttribute('something'
, array('hash' => $hash,'name' => $name));
With the first example, we can use hasAttribute('name') to check if it's set and with the second example, we will need two lines of code for such check. E.g. Methods like hasAttribute('name') will not work:
$something = $this->getUser()->getAttribute('something');
if($something['name']) //...
Also, setting new value to variable requires more lines:
$something['name'] = 'New value';
$this->getUser()->setAttribute('something', $something);
But the benefit of having an Arrays for to store sessions is the ability to clear the whole Array at once.
Maybe it's possible to manipulate Arrays the better way which I'm not aware of? Or maybe I'm wrong with my statements at all... What is the best practice?