Session handling

Permalink
Using version 5.7.4.2:

It is just an opinion based question. Is it?

I use session handling like this:
$session = \Core::make('session');
$session->set('foo', 'bar');
$session->get('foo'); // gives 'bar'
$session->remove('foo');

Now I've read the following HowTo:
https://www.concrete5.org/documentation/how-tos/developers/session-h...
which says to use sessions as follows:
use \Symfony\Component\HttpFoundation\Session\Session as SymfonySession;
$session = new SymfonySession();
$session->set('foo', 'bar');
$session->get('foo'); // gives 'bar'
$session->remove('foo');


Both solutions reach exactly the same goal.
Now my question is: Which one is better, cleaner, recommended?

daenu
 
MrKDilkington replied on at Permalink Best Answer Reply
MrKDilkington
Hi pcshooter,

I've read that it is recommended to use the built-in helper services. One reason was there are fewer breaking changes in your code if there is a change to core code.

Core::make('session')
'session' is an instance of \Symfony\Component\HttpFoundation\Session\Session
- this looks to do the same thing, but with less code
daenu replied on at Permalink Reply
daenu
Thank you!