diff --git a/helper.php b/helper.php index 12683cfd82..98e404ea8b 100644 --- a/helper.php +++ b/helper.php @@ -103,7 +103,7 @@ function lang($name, $vars = [], $lang = '') function config($name = '', $value = null, $range = '') { if (is_null($value) && is_string($name)) { - return 0 === strpos($name, '?') ? Config::has(substr($name, 1), $range) : Config::get($name, $range); + return isset($name[0]) && $name[0] == '?' ? Config::has(substr($name, 1), $range) : Config::get($name, $range); } else { return Config::set($name, $value, $range); } @@ -120,7 +120,7 @@ function config($name = '', $value = null, $range = '') */ function input($key = '', $default = null, $filter = '') { - if (0 === strpos($key, '?')) { + if (isset($key[0]) && $key[0] == '?') { $key = substr($key, 1); $has = true; } @@ -301,7 +301,7 @@ function session($name, $value = '', $prefix = null) Session::clear('' === $value ? null : $value); } elseif ('' === $value) { // 判断或获取 - return 0 === strpos($name, '?') ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix); + return isset($name[0]) && $name[0] == '?' ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix); } elseif (is_null($value)) { // 删除 return Session::delete($name, $prefix); @@ -330,7 +330,7 @@ function cookie($name, $value = '', $option = null) Cookie::clear($value); } elseif ('' === $value) { // 获取 - return 0 === strpos($name, '?') ? Cookie::has(substr($name, 1), $option) : Cookie::get($name, $option); + return isset($name[0]) && $name[0] == '?' ? Cookie::has(substr($name, 1), $option) : Cookie::get($name, $option); } elseif (is_null($value)) { // 删除 return Cookie::delete($name); @@ -366,11 +366,11 @@ function cache($name, $value = '', $options = null, $tag = null) return $cache->clear($value); } elseif ('' === $value) { // 获取缓存 - return 0 === strpos($name, '?') ? $cache->has(substr($name, 1)) : $cache->get($name); + return isset($name[0]) && $name[0] == '?' ? $cache->has(substr($name, 1)) : $cache->get($name); } elseif (is_null($value)) { // 删除缓存 return $cache->rm($name); - } elseif (0 === strpos($name, '?') && '' !== $value) { + } elseif (isset($name[0]) && $name[0] == '?' && '' !== $value) { $expire = is_numeric($options) ? $options : null; return $cache->remember(substr($name, 1), $value, $expire); } else { diff --git a/library/think/Template.php b/library/think/Template.php index 9ba0ff35bf..5a54723df4 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -474,12 +474,30 @@ private function parseInclude(&$content) unset($array['file']); // 分析模板文件名并读取内容 $parseStr = $this->parseTemplateName($file); + //[SWH|+]删掉必须替换掉的占位符==\ + $mustReplaces = []; + $parseStr = preg_replace_callback('{^[\s]*<\\!\\-\\-[\s]*()[\s]*\\-\\->[\s]*}',function($p)use(&$mustReplaces){ + $mustReplaces = $this->parseAttr($p[1]); + return ''; + },$parseStr); + //===========================/ foreach ($array as $k => $v) { // 以$开头字符串转换成模板变量 if (0 === strpos($v, '$')) { $v = $this->get(substr($v, 1)); } $parseStr = str_replace('[' . $k . ']', $v, $parseStr); + if($mustReplaces && isset($mustReplaces[$k])) unset($mustReplaces[$k]);//[SWH|+]删掉必须替换掉的占位符 + } + //[SWH|+]删掉必须替换掉的占位符 + if($mustReplaces){ + foreach ($mustReplaces as $k => $v) { + // 以$开头字符串转换成模板变量 + if (0 === strpos($v, '$')) { + $v = $this->get(substr($v, 1)); + } + $parseStr = str_replace('[' . $k . ']', $v, $parseStr); + } } $content = str_replace($match[0], $parseStr, $content); // 再次对包含文件进行模板分析 diff --git a/library/think/console/command/optimize/Autoload.php b/library/think/console/command/optimize/Autoload.php index 6a77c2cbaf..9af89c0f2b 100644 --- a/library/think/console/command/optimize/Autoload.php +++ b/library/think/console/command/optimize/Autoload.php @@ -279,9 +279,9 @@ protected function findClasses($path) $namespace = str_replace([' ', "\t", "\r", "\n"], '', $matches['nsname'][$i]) . '\\'; } else { $name = $matches['name'][$i]; - if ($name[0] === ':') { + if (isset($name[0]) && $name[0] == ':') { $name = 'xhp' . substr(str_replace(['-', ':'], ['_', '__'], $name), 1); - } elseif ($matches['type'][$i] === 'enum') { + } elseif ($matches['type'][$i] == 'enum') { $name = rtrim($name, ':'); } $classes[] = ltrim($namespace . $name, '\\');

AltStyle によって変換されたページ (->オリジナル) /