From c64a33588429553da4ceb0a645bfccaec8a826ed Mon Sep 17 00:00:00 2001 From: HyperQing <469379004@qq.com> Date: Fri, 21 Oct 2016 11:36:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BARequest=E7=B1=BB=E7=9A=84=E5=87=A0?= =?UTF-8?q?=E4=B8=AA=E6=96=B9=E6=B3=95=E5=AE=8C=E5=96=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在phpstorm2016.2.1中,使用下列语句会提示警告: >Method __toString is not implemented for '\think\Request' less... (Ctrl+F1) This inspection detects attempts to convert objects without __toString() method implementation to string, since PHP 5.2.0, it would cause E_RECOVERABLE_ERROR. "Check __toString exists for each expression type": if the option is on, the inspection will check all possible types of the expression and report if at least one ot them doesn't contain __toString() method implementation. ``` $request = Request::instance(); echo "当前模块名称是" . $request->module();// 这句会被IDE提示警告 echo "当前控制器名称是" . $request->controller();// 这句会被IDE提示警告 echo "当前操作名称是" . $request->action();// 这句就不会 ``` 后来发现是注释引起的问题,注释中有@return string|$this。而action()方法却写成@return string。个人认为应该统一写成@return string|Request 比较合适。学识短浅,仅供参考 ``` /** * 设置或者获取当前的模块名 * @access public * @param string $module 模块名 * @return string|$this */ public function module($module = null) ``` --- library/think/Request.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index 35803e3f..bc43eb2f 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -1370,7 +1370,7 @@ class Request * 设置或者获取当前的模块名 * @access public * @param string $module 模块名 - * @return string|$this + * @return string|Request */ public function module($module = null) { @@ -1386,7 +1386,7 @@ class Request * 设置或者获取当前的控制器名 * @access public * @param string $controller 控制器名 - * @return string|$this + * @return string|Request */ public function controller($controller = null) { @@ -1402,7 +1402,7 @@ class Request * 设置或者获取当前的操作名 * @access public * @param string $action 操作名 - * @return string + * @return string|Request */ public function action($action = null) { @@ -1418,7 +1418,7 @@ class Request * 设置或者获取当前的语言 * @access public * @param string $lang 语言名 - * @return string + * @return string|Request */ public function langset($lang = null) {