There is a function:

/** * * Summary * * Description * * @param string $message Description * * @return void * */ function say( $message = 'hi' ) { echo $message; } 

How to specify in PHPDoc that the $message parameter is optional and has the value hi ?


I found the same questions in the English-speaking community, but they all refer to the following paragraph from the documentation:

Note that the $ paramname, ... will be shown in the output listing of the function signature. If the parameter is not defined, it should be noted that the parameter is optional.

This paragraph, unfortunately, I can not understand:

Note that $paramname,... will be shown in the resulting documentation, both in the parameter listing and in the function signature. If you do not designate this parameter as optional in real code (using “$ paramname = 'default value'), then you should mention in the parameter description that the parameter is optional.


I tried to specify this:

 /** * * @param string $message,... Description * */ 

But my NetBeans highlights it as a “Wrong Param Name.”


For example, in JSDoc this is done like this:

 /** * * @param {string} [message=hi] Description * */ 

I tried by analogy:

 /** * * @param string [$message] Description * * ... * * @param string [$message=hi] Description * * ... * * @param string [$message='hi'] Description * * ... * * @param string [$message="hi"] Description * */ 

But nothing comes out: NetBeans shows the name of the parameter in the description, and not as the name of the parameter.


UPD

I didn’t immediately see something from others: I looked into the Yii documentation, in particular in one method: ActiveForm :: begin () ; but there the developers do not designate the optional parameter $config = [] ?

    1 answer 1

    You have already set the default parameter "Hi"

     $message = 'hi' 
    • And how to specify it in PHPDoc: for example, I encode in another file; I look - function; I call the documentation on it (Ctrl + CursorHover), but the documentation does not say anything about the optional and the default value. - Roman Grinyov
    • one
      @RomanGrinyov is already a problem of the documentation and metadata manager. The default value is already specified in the code, no additional action is required. - etki