【发布时间】:2013-11-21 03:27:38
【问题描述】:
我是 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,但事实并非如此。这是为什么呢?
【问题讨论】:
-
它看起来确实像一个错误。您应该在github.com/phalcon/cphalcon/issues 上报告此问题