When using constructor property promotion, the most natural place to add docblock information about both the parameter and the property is to do it as a normal constructor docblock and use the @param like you would if it were a normal parameter. I do this a lot, especially when I want to add Psalm annotations. It works well because Psalm does understand that these @param annotations refer both the parameter and the property.
I discovered that when using the rename refactor feature in VSCode for a parameter like this, it does not rename the parameter name in the docblock like it normally would if it were not a constructor property promotion parameter. It seemed like I was having a lot of intermittent problems when renaming parameters and properties, but now between these last 3 issues I filed here, I finally have figured out exactly what is happening in reproducible ways.
Here is some example code.
<?php
declare(strict_types=1);
namespace MyNamespace;
class MyClass
{
/**
* @param list<int> $numList
*/
public function __construct(private array $numList) {
}
}
When using constructor property promotion, the most natural place to add docblock information about both the parameter and the property is to do it as a normal constructor docblock and use the
@paramlike you would if it were a normal parameter. I do this a lot, especially when I want to add Psalm annotations. It works well because Psalm does understand that these@paramannotations refer both the parameter and the property.I discovered that when using the rename refactor feature in VSCode for a parameter like this, it does not rename the parameter name in the docblock like it normally would if it were not a constructor property promotion parameter. It seemed like I was having a lot of intermittent problems when renaming parameters and properties, but now between these last 3 issues I filed here, I finally have figured out exactly what is happening in reproducible ways.
Here is some example code.