Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPDoc optional parameter

Strictly speaking, PHP doesn't know "optional parameters", but parameters with default values, that can be omitted when the function or method is called. OK, that's at the end an optional parameter, but your

@param string $encoding Encoding.

is completely correct here, because the default value is a string. What the documentation tries to tell you is that you should mention it yourself like

@param string $encoding (optional) Encoding.

I agree with you, that a notation like

__construct([$encoding])

or

__construct($encoding = 'UTF-8')

would be nice. You can post a bug report

https://github.com/phpDocumentor/phpDocumentor2/issues?state=open

Update: Realised, that this already mentioned https://github.com/phpDocumentor/phpDocumentor2/search?q=optional&type=Issues