8000 [Session] MockArraySessionStorage: clear(): error when no bags · Issue #21990 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content < 8000 span data-view-component="true" class="progress-pjax-loader Progress position-fixed width-full">
[Session] MockArraySessionStorage: clear(): error when no bags #21990
Closed
< 759C a class="Avatar-module__avatarLink--S36bm Avatar-module__avatarOuter--MZJZH prc-Link-Link-85e08" href="https://github.com/MacDada" data-hovercard-url="/users/MacDada/hovercard" aria-label="@MacDada's profile">@MacDada

Description

@MacDada
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 2.7+

https://github.com/symfony/http-foundation/blob/2.7/Session/Storage/MockArraySessionStorage.php#L175

clear() iterates over list of bags, but… sometimes there are no bags and it results in PHP error:

Invalid argument supplied for foreach()

How to get that error?

$storage = new MockArraySessionStorage();
$storage->clear();

I stumbled upon this then I was writing a test to reproduce #7104:

public function testLogout(Client $client)
{
    $client->getKernel()->boot();
    $client->getContainer()->get('session.storage.filesystem')->clear();
    $client->request('GET', '/logout');

Possible solutions:

  • a.) Throw exception instead of having PHP error (message could say what's wrong).
  • b.) Return early when $this->bags is null.
  • c.) Always keep $this->bags as array (instead of possible null).

b and c could be considered BC if someone relied upon this "not working" (but I'd say the chances are low).


After it is decided what to do with this issue, I can create PR with test and implementation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0