Skip to content

Commit fe78406

Browse files
scottwarrenweaverryan
scottwarren
authored andcommitted
Added Caution note
1 parent 13aeea7 commit fe78406

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

components/http_foundation/sessions.rst

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@ object-oriented interface using a variety of session storage drivers.
1212
Sessions are used via the simple :class:`Symfony\\Component\\HttpFoundation\\Session\\Session`
1313
implementation of :class:`Symfony\\Component\\HttpFoundation\\Session\\SessionInterface` interface.
1414

15+
.. caution::
16+
17+
Make sure your Sessions aren't already initliazed (which in Symfony is done automatically),
18+
as initializing the Session object causes the session to be started, which can lead to unexpected errors.
19+
1520
Quick example::
1621

17-
$session = $this->getRequest()->getSession();
22+
use Symfony\Component\HttpFoundation\Session\Session;
23+
24+
$session = new Session();
1825
$session->start();
1926

2027
// set and get session attributes
@@ -287,7 +294,9 @@ to be used for more complex messaging in your application.
287294

288295
Examples of setting multiple flashes::
289296

290-
$session = $this->getRequest()->getSession();
297+
use Symfony\Component\HttpFoundation\Session\Session;
298+
299+
$session = new Session();
291300
$session->start();
292301

293302
// add flash messages

0 commit comments

Comments
 (0)