无法从Phalcon持久存储中删除属性(会话包)

时间:2013-11-21 03:27:38

标签: php session phalcon

我是Phalcon PHP框架的新手,目前我正在尝试使用Controller中的持久存储(通过$this->persistent访问)。我知道持久存储使用Session \ Bag,根据the API我可以通过remove()__unset魔术方法移除属性。 所以,我创建了这个小控制器来测试持久存储:

<?php

class Control1Controller extends Phalcon\Mvc\Controller
{
    public function cobaAction()
    {
        echo '<pre>';
        $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";
    }
}

当我访问该操作时,这是我得到的结果:

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

现在这很奇怪,我希望在致电->remove('anu')并设置anu = null后,has()isset()会返回false,但事实并非如此。那是为什么?

1 个答案:

答案 0 :(得分:1)