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

Zend\Session::AbstractContainer::offsetExists() returning FALSE for key with NULL value #5

Open
weierophinney opened this issue Dec 31, 2019 · 1 comment

Comments

@weierophinney
Copy link
Member

@weierophinney @Ocramius

As said in the title, checking if specific offset exists when it is set with NULL value always return FALSE.

// Zend session container
$session = Application::getInstance()->getSession();
$session['key'] = NULL;
if($session->offsetExists('key')) {
        // do something
}

The problem is that current implementation rely on PHP isset() language construct which return FALSE for keys with NULL value. Shouldn't it be preferable to use the PHP array_key_exists() function? What we want there is knonwing if a specific offset exists, whatever it value, right? Else, is there any reliable way to check if a particular key was set, whatever it value and without first having to get an array copy?

Even worse is that trying to unset an offset with NULL value will lead to a NO OP because we return early from Zend\Session::AbstractContainer::offsetUnset() if the offset isn't set in regard of the Zend\Session::AbstractContainer::offsetExists() current implementation:

// Zend session container
$session = Application::getInstance()->getSession();
$session['key'] = NULL;
$session->offsetUnset('key'); NO OP... Key will still be in storage...

Thank you.


Originally posted by @nuxwin at zendframework/zend-session#111

@weierophinney
Copy link
Member Author

I think you are right. There should be a difference between a key is set and key exist. Maybe one can implement another method with name offsetIsSet, which uses isset and change method offsetExists to use array_key_exists.


Originally posted by @dennybrandes at zendframework/zend-session#111 (comment)

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

1 participant