clear() public static méthode

清空session数据
public static clear ( string | null $prefix = null ) : void
$prefix string | null 作用域(前缀)
Résultat void
Exemple #1
0
function session($name, $value = '')
{
    if (is_array($name)) {
        // 初始化
        \think\Session::init($name);
    } elseif (is_null($name)) {
        // 清除
        \think\Session::clear($value);
    } elseif ('' === $value) {
        // 获取
        return \think\Session::get($name);
    } elseif (is_null($value)) {
        // 删除session
        return \think\Session::delete($name);
    } else {
        // 设置session
        return \think\Session::set($name, $value);
    }
}
Exemple #2
0
 /**
  * Session管理
  * @param string|array  $name session名称,如果为数组表示进行session设置
  * @param mixed         $value session值
  * @param string        $prefix 前缀
  * @return mixed
  */
 function session($name, $value = '', $prefix = null)
 {
     if (is_array($name)) {
         // 初始化
         Session::init($name);
     } elseif (is_null($name)) {
         // 清除
         Session::clear('' === $value ? null : $value);
     } elseif ('' === $value) {
         // 判断或获取
         return 0 === strpos($name, '?') ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix);
     } elseif (is_null($value)) {
         // 删除
         return Session::delete($name, $prefix);
     } else {
         // 设置
         return Session::set($name, $value, $prefix);
     }
 }
Exemple #3
0
 /**
  * @covers think\Session::clear
  *
  * @todo Implement testClear().
  */
 public function testClear()
 {
     \think\Session::prefix(null);
     \think\Session::set('sessionnameclsper', 'sessionvalue1', 'think_');
     \think\Session::clear('think_');
     $this->assertNull($_SESSION['think_']);
     \think\Session::set('sessionnameclsper', 'sessionvalue1', 'think_');
     \think\Session::clear();
     $this->assertEmpty($_SESSION);
 }
Exemple #4
0
function session($name, $value = '', $prefix = null)
{
    if (is_array($name)) {
        // 初始化
        \think\Session::init($name);
    } elseif (is_null($name)) {
        // 清除
        \think\Session::clear($value);
    } elseif ('' === $value) {
        // 判断或获取
        return 0 === strpos($name, '?') ? \think\Session::has(substr($name, 1), $prefix) : \think\Session::get($name, $prefix);
    } elseif (is_null($value)) {
        // 删除session
        return \think\Session::delete($name, $prefix);
    } else {
        // 设置session
        return \think\Session::set($name, $value, $prefix);
    }
}