From 848824c86a54ca24f62a0f0958d6fe142c83329a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 18 Feb 2016 10:53:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9Bcookie=E5=92=8Csession?= =?UTF-8?q?=E7=B1=BB=E7=9A=84prefix=E5=8F=82=E6=95=B0=E5=88=A4=E6=96=AD=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BC=A0=E5=85=A5=E7=A9=BA=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Cookie.php | 18 +++++++++--------- library/think/Session.php | 30 +++++++++++++++--------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/library/think/Cookie.php b/library/think/Cookie.php index bf4bd64a..9269cf68 100644 --- a/library/think/Cookie.php +++ b/library/think/Cookie.php @@ -97,12 +97,12 @@ class Cookie /** * Cookie获取 * @param string $name cookie名称 - * @param string $prefix cookie前缀 + * @param string|null $prefix cookie前缀 * @return mixed */ - public static function get($name, $prefix = '') + public static function get($name, $prefix = null) { - $prefix = $prefix ? $prefix : self::$config['prefix']; + $prefix = !is_null($prefix) ? $prefix : self::$config['prefix']; $name = $prefix . $name; if (isset($_COOKIE[$name])) { $value = $_COOKIE[$name]; @@ -120,13 +120,13 @@ class Cookie /** * Cookie删除 * @param string $name cookie名称 - * @param string $prefix cookie前缀 + * @param string|null $prefix cookie前缀 * @return mixed */ - public static function delete($name, $prefix = '') + public static function delete($name, $prefix = null) { $config = self::$config; - $prefix = $prefix ? $prefix : $config['prefix']; + $prefix = !is_null($prefix) ? $prefix : $config['prefix']; $name = $prefix . $name; if (self::$config['setcookie']) { setcookie($name, '', time() - 3600, $config['path'], $config['domain'], $config['secure'], $config['httponly']); @@ -137,10 +137,10 @@ class Cookie /** * Cookie清空 - * @param string $prefix cookie前缀 + * @param string|null $prefix cookie前缀 * @return mixed */ - public static function clear($prefix = '') + public static function clear($prefix = null) { // 清除指定前缀的所有cookie if (empty($_COOKIE)) { @@ -149,7 +149,7 @@ class Cookie // 要删除的cookie前缀,不指定则删除config设置的指定前缀 $config = self::$config; - $prefix = $prefix ? $prefix : $config['prefix']; + $prefix = !is_null($prefix) ? $prefix : $config['prefix']; if ($prefix) { // 如果前缀为空字符串将不作处理直接返回 foreach ($_COOKIE as $key => $val) { diff --git a/library/think/Session.php b/library/think/Session.php index ef2b46b7..853413b4 100644 --- a/library/think/Session.php +++ b/library/think/Session.php @@ -101,12 +101,12 @@ class Session * * @param string $name session名称 * @param mixed $value session值 - * @param string $prefix 作用域(前缀) + * @param string|null $prefix 作用域(前缀) * @return void */ - public static function set($name, $value = '', $prefix = '') + public static function set($name, $value = '', $prefix = null) { - $prefix = $prefix ? $prefix : self::$prefix; + $prefix = !is_null($prefix) ? $prefix : self::$prefix; if (strpos($name, '.')) { // 二维数组赋值 list($name1, $name2) = explode('.', $name); @@ -126,12 +126,12 @@ class Session * session获取 * * @param string $name session名称 - * @param string $prefix 作用域(前缀) + * @param string|null $prefix 作用域(前缀) * @return mixed */ - public static function get($name = '', $prefix = '') + public static function get($name = '', $prefix = null) { - $prefix = $prefix ? $prefix : self::$prefix; + $prefix = !is_null($prefix) ? $prefix : self::$prefix; if ('' == $name) { // 获取全部的session $value = $prefix ? (!empty($_SESSION[$prefix]) ? $_SESSION[$prefix] : []) : $_SESSION; @@ -158,12 +158,12 @@ class Session * 删除session数据 * * @param string $name session名称 - * @param string $prefix 作用域(前缀) + * @param string|null $prefix 作用域(前缀) * @return void */ - public static function delete($name, $prefix = '') + public static function delete($name, $prefix = null) { - $prefix = $prefix ? $prefix : self::$prefix; + $prefix = !is_null($prefix) ? $prefix : self::$prefix; if (strpos($name, '.')) { list($name1, $name2) = explode('.', $name); if ($prefix) { @@ -183,12 +183,12 @@ class Session /** * 清空session数据 * - * @param string $prefix 作用域(前缀) + * @param string|null $prefix 作用域(前缀) * @return void */ - public static function clear($prefix = '') + public static function clear($prefix = null) { - $prefix = $prefix ? $prefix : self::$prefix; + $prefix = !is_null($prefix) ? $prefix : self::$prefix; if ($prefix) { unset($_SESSION[$prefix]); } else { @@ -200,14 +200,14 @@ class Session * 判断session数据 * * @param string $name session名称 - * @param string $prefix + * @param string|null $prefix * * @return bool * @internal param mixed $value session值 */ - public static function has($name, $prefix = '') + public static function has($name, $prefix = null) { - $prefix = $prefix ? $prefix : self::$prefix; + $prefix = !is_null($prefix) ? $prefix : self::$prefix; if (strpos($name, '.')) { // 支持数组 list($name1, $name2) = explode('.', $name);