kotfire/vscode-php-add-property

Nullable property types are stripped when adding existing property

Closed this issue · 1 comments

Hello

Adding an existing property with a nullable PHP 7.4 to the constructor will ignore the nullable type hint:

/**
 * @var string|null
 */
private ?string $blah;

This will result in:

/**
 * Constructor.
 * @param string $blah
 */
public function __construct(string  $blah)
{
    $this->blah = $blah;
}

Where $blah is a string instead of a string|null in the docblock and a ?string in the constructor parameter.

PS: You may also be interested in knowing that PHP 8 will support union types, so types such as these become valid as well (they may already work):

private int|string $value;

Thanks!

Added in v1.1.0