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

[BUG] Cannot Remove A Property From Phalcon Persistent Storage (Session Bag) #1637

Closed
captainkuro opened this issue Dec 5, 2013 · 6 comments

Comments

@captainkuro
Copy link

I originally asked this on stackoverflow. I don't know if this is a bug or not.

I'm new to Phalcon PHP framework and currently I'm trying to use the persistent storage in Controller (accessed via $this->persistent). I know that persistent storage uses Session\Bag and according to the API I can remove a property via remove() or __unset magic method. So, I create this little Controller to test the persistent storage:

class Control1Controller extends Phalcon\Mvc\Controller
{
    public function cobaAction()
    {
        $this->persistent->destroy();
        $this->dump('anu');
        echo "Set\n";
        $this->persistent->anu = 'Aloha';
        $this->dump('anu');
        echo "Remove\n";
        $this->persistent->remove('anu');
        $this->dump('anu');
        echo "set\n";
        $this->persistent->anu = 'Aloha';
        $this->dump('anu');
        echo "assign null\n";
        $this->persistent->anu = null;
        $this->dump('anu');
        echo "set\n";
        $this->persistent->anu = 'Aloha';
        $this->dump('anu');
        echo "destroy\n";
        $this->persistent->destroy();
        $this->dump('anu');
    }

    private function dump($anu)
    {
        echo $anu.'='.var_export($this->persistent->$anu, true)."\n";
        echo 'has('.$anu.')='.var_export($this->persistent->has($anu), true)."\n";
        echo 'isset('.$anu.')='.var_export(isset($this->persistent->$anu), true)."\n";
        echo "\n";
    }
}

When I access that action, this is the result I got:

anu=NULL
has(anu)=false
isset(anu)=false

Set
anu='Aloha'
has(anu)=true
isset(anu)=true

Remove
anu='Aloha'
has(anu)=true
isset(anu)=true

set
anu='Aloha'
has(anu)=true
isset(anu)=true

assign null
anu=NULL
has(anu)=true
isset(anu)=true

set
anu='Aloha'
has(anu)=true
isset(anu)=true

destroy
anu=NULL
has(anu)=false
isset(anu)=false

Now that's strange, I expect after calling ->remove('anu') and setting anu = null, the has() and isset() would return false, but it didn't. Why is that?

@ghost
Copy link

ghost commented Dec 5, 2013

Confirmed, both 1.2.5 and 1.3.0

@ghost
Copy link

ghost commented Dec 5, 2013

has and isset will always return the same value as they are both implemented by the same method.

They both act much like array_key_exists() returning true if the property exists but is null.

This was referenced Dec 5, 2013
@khandar-william
Copy link

sjinks commented 43 minutes ago
has and isset will always return the same value as they are both implemented by the same method.

They both act much like array_key_exists() returning true if the property exists but is null.

Okay, maybe that is the intended behavior.
But, why after calling ->persistent->remove('anu') the value of ->persistent->anu is still 'Aloha'?

@ghost
Copy link

ghost commented Dec 5, 2013

There are two PRs open to fix this :-)

phalcon pushed a commit that referenced this issue Dec 5, 2013
phalcon pushed a commit that referenced this issue Dec 5, 2013
@ghost
Copy link

ghost commented Dec 11, 2013

I think this can be closed now?

@captainkuro
Copy link
Author

Yes, thank you very much

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

3 participants