cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[NFR] Phalcon\Session\Bag::remove($index) method

Open alvassin opened this issue 13 years ago • 4 comments

It would be nice to have it, as it exists in Phalcon\Session\Adapter\Files class.

P.S. Also it would be nice to return boolean in this method - e.g. if index is not defined - method should return false.

smth like this (as example in extended class i'm currently using)

class Bag extends Phalcon\Session\Bag
{
    public function remove($index)
    {
        if (isset($_SESSION[$this->_name][$index])) {
            unset($_SESSION[$this->_name][$index]);
            return true;
        }
        return false;
    }
}

alvassin avatar Feb 01 '13 16:02 alvassin

You can use $bag->destroy()

ghost avatar Feb 01 '13 21:02 ghost

$bag->destroy() destroys whole bag, in some cases it's more usable to remove an index.

e.g. i have a service, that handles current user (session) and all it's states. when this service starts, it checks if $bag->has('somedata'). If bag does have, it performs some operations (db calls, etc), if doesn't - it does nothing.

If i will use $bag->set('somedata', null); - $bag->has('somedata') will return "true", so some extra db queries will be executed

Just as idea to think about, perhaps it is very rare case :)

alvassin avatar Feb 01 '13 22:02 alvassin

+1

jarvischen avatar Feb 02 '13 02:02 jarvischen

This was addressed in 1.0.0, thanks

ghost avatar Feb 20 '13 22:02 ghost