bmewburn / intelephense-docs

Documentation for the Intelephense PHP language server
https://intelephense.com
Other
184 stars 17 forks source link

Variable Arguments with PHPDoc: Variable gets extra array dimension #56

Open DABugh opened 1 year ago

DABugh commented 1 year ago

Short version: for function(string ...$vars) with PHPDoc, $vars is interpreted as string[][].


Consider the function:

function FunctionWithoutPHPDoc(string ...$stringArray)
{
    var_dump($stringArray);
}

$stringArray is declared as an array of strings. The hover text correctly identifies it as such:

@param string[] ...$stringArray

However, adding a PHPDoc changes how Intelephense recognizes the variable type.

Press Ctrl+. and select "Add PHPDoc" to produce this code block:

/**
 * @param string[] $stringArray 
 * 
 * @return void 
 */
function FunctionWithPHPDoc(string ...$stringArray)
{
    var_dump($stringArray);
}

(the function has been renamed in this example, obviously, but that is irrelevant to the issue)

The hover text now displays:

@param string[][] $stringArray