think\Session::pull PHP Method

pull() public static method

session获取并删除
public static pull ( string $name, string | null $prefix = null ) : mixed
$name string session名称
$prefix string | null 作用域(前缀)
return mixed
    public static function pull($name, $prefix = null)
    {
        $result = self::get($name, $prefix);
        if ($result) {
            self::delete($name, $prefix);
            return $result;
        } else {
            return null;
        }
    }

Usage Example

Exemplo n.º 1
0
 public function testPull()
 {
     Session::prefix(null);
     Session::set('sessionnamedel', 'sessionvalue');
     $this->assertEquals('sessionvalue', Session::pull('sessionnameget'));
     $this->assertNull(Session::get('sessionnameget'));
 }