Skip to content

Commit 52d1c55

Browse files
committed
minor #16985 Adding that you cannot access a session inside a constructor (ThomasLandauer)
This PR was submitted for the 6.1 branch but it was squashed and merged into the 5.4 branch instead. Discussion ---------- Adding that you cannot access a session inside a constructor Please double-check! The info is taken from PhpStorm's Symfony Plugin: https://espend.de/phpstorm/plugin/symfony#inspections: > A Session must not be used inside a constructor I think this should be explained here, since doing `$this->session = $requestStack->getSession();` right in the constructor looked like a nice idea... Commits ------- 9f3b147 Adding that you cannot access a session inside a constructor
2 parents ca7e57e + 9f3b147 commit 52d1c55

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

session.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ if you type-hint an argument with :class:`Symfony\\Component\\HttpFoundation\\Re
149149
public function __construct(RequestStack $requestStack)
150150
{
151151
$this->requestStack = $requestStack;
152+
153+
// Accessing the session in the constructor is *NOT* reommended, since
154+
// it might not be accessible yet or lead to unwanted side-effects
155+
// $this->session = $requestStack->getSession();
152156
}
153157

154158
public function someMethod()

0 commit comments

Comments
 (0)