php / phpDoc - @return instance of $this class?

前端 未结 5 1484
温柔的废话
温柔的废话 2021-02-07 16:08

How do I mark a method as \"returns an instance of the current class\" in my phpDoc?

In the following example my IDE (Netbeans) will see that setSomething always returns

5条回答
  •  执笔经年
    2021-02-07 16:31

    phpDoc syntax allows for multiple types to be defined by separating them with a | character for the @return tag. When you extend the class foo with class bar you should write a new phpDoc tag that has the proper class for its @return.

    If a function returns either foo or bar then you would use @return foo|bar.

    However in your case just define @return bar for the overridden function.

    Take care.

提交回复
热议问题