$this, the element to which this type applies is the same exact instance as the current class in the given context. As such this type is a stricter version of static as, in addition, the returned instance must not only be of the same class but also the same instance.
This type is often used as return value for methods implementing the Fluent Interface design pattern.
This notation is currently used by popular IDEs such as PhpStorm and Netbeans.
发布评论
评论(4)
PHP 标准建议 (PSR) 目前处于草案中 (PSR-5) 提议 @返回$this 用于指示返回相同的实例。
此表示法目前由 PhpStorm 和 Netbeans 等流行 IDE 使用。
There is a PHP Standards Recommendation (PSR) currently in draft (PSR-5) that proposes @return $this is used in order to indicate that the same instance is returned.
This notation is currently used by popular IDEs such as PhpStorm and Netbeans.
@return Current_Class_Name
肯定会起作用,并且是我更喜欢的。@return self
也可以在某些程序中正常工作。@return this
不好,因为这不是类型名。@return Current_Class_Name
will definitely work and is what I prefer.@return self
may work ok with some programs too.@return this
is bad because this is not a typename.这个问题很老了,但我只是想分享给大家!
至少对于那些使用 NetBeans 8.1 的人来说。这个表示法使得代码自动完成功能在 IDE 中很好地工作:
我说至少适用于 NetBeans8.1 用户,但可能也适用于旧版本和/或其他 IDE =]
This question is quite old, but I just want to share to everyone!
AT LEAST for the ones that uses NetBeans 8.1.. this notation makes code autocompletion to nicely work at IDE:
I say AT LEAST for NetBeans8.1 users, but may work on older versions and/or others IDEs too =]
您可以使用“self”类型作为@param或@return。PHPDoc
建议“self”在对象中引用self。
来源:http://www.phpdoc.org/docs/latest/references/phpdoc/types.html
You can use "self" type as @param or @return..
PHPDoc recommends 'self' to refer to self in object..
Source: http://www.phpdoc.org/docs/latest/references/phpdoc/types.html