Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with ArrayAccess storage #37

Open
sverlan opened this issue Mar 10, 2018 · 1 comment
Open

Problems with ArrayAccess storage #37

sverlan opened this issue Mar 10, 2018 · 1 comment

Comments

@sverlan
Copy link

sverlan commented Mar 10, 2018

When using an ArrayAccess storage (I'm using adbario/slim-secure-session-middleware) the addMessage fails to write the message to the storage. The problem is that with ArrayAccess double indexing cannot be used:

$this->storage[$this->storageKey][$key] = array();

has no effect. Instead the following should be used:

$temp = $this->storage[$this->storageKey];
$temp[$key] = array();
$this->storage[$this->storageKey] =$temp;

I made a small modification to addMessage which seems to work:

public function addMessage($key, $message)
    {
       // Workaround for ArrayAccess storage
        $temp = $this->storage[$this->storageKey];
        // Create Array for this key
        if (!isset($temp[$key])) {
            $temp[$key] = [];
        }
        // Push onto the array
        $temp[$key][] = $message;
        $this->storage[$this->storageKey] = $temp;
    }
@ntzm
Copy link

ntzm commented Jun 19, 2020

If you have control of the ArrayAccess implementation, you can add a & to the offsetGet implementation to solve this.

public function &offsetGet($offset)
{

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants