Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpdoc for inherited method

I have class A with some method that returns bool value. I made phpdoc for that method.

I made another class B which extends class A and overrides method. New method returns string. (I understand that in common case change the return type is not a good idea, but in my case it's a good way.)

I want to make phpdoc for new method. I could use {@inheritDoc}, but it takes full phpdoc from old method. I want to take from old phpdoc general method description and specification of arguments, but change description of return value.

How could I do it?

like image 801
Victor Mezrin Avatar asked Jun 05 '14 16:06

Victor Mezrin


People also ask

What is@ inheritDoc?

The @inheritdoc tag indicates that a symbol should inherit its documentation from its parent class. Any other tags that you include in the JSDoc comment will be ignored. This tag is provided for compatibility with Closure Compiler.

What is@ inheritDoc php?

The {@inheritdoc} inline tag is used in the class DocBlocks of child classes. phpDocumentor will automatically inherit the @author tag, @version tag, and @copyright tag from a parent class. {@inheritdoc} allows flexibility of where to put documentation from the parent class in a child class's documentation.


1 Answers

Based on the phpDocumentor manual for inheritance methods will inherit without the need for an inline {@inheritDoc} tag and you can override tags as you see fit.

Inheritance for methods functions similar to classes and interfaces. When a superclass of the current class contains a method with the same name (hence, this method is re-defined) then the following information is inherited from that overridden method:

  • Summary
  • Description
  • The following tags:
    • author
    • copyright
    • version
    • param
    • return
    • throws

As with classes, each of the above will only be inherited if the redefined method’s DocBlock does not have the element that is to be inherited. So, for example, if the DocBlock of the redefined method has a summary then it will not receive the overridden method’s summary.

However from experience IDE's handle parsing this data in their own way and hence results may vary. For example, in IntelliJ/PHPStorm the parent method docs will be inherited but you can either override everything or nothing.

like image 158
Kirill Fuchs Avatar answered Oct 13 '22 23:10

Kirill Fuchs