vscode-intelephense
vscode-intelephense copied to clipboard
PHPDoc @var popup missing description with global statements
Describe the bug
Hover popup doesn't show the PHPDoc description when the PHPDoc is next to a global
statement. If it is next to an assignment, it works fine.
To Reproduce
<?php
/** @var bool $var1 description goes here */
global $var1;
/** @var bool $var2 description goes here */
$var2 = NULL;
global $var1;
global $var2;
?>
Expected behavior The description appears in both hover popups.
Screenshots
Platform and version Windows 10 1909 x64 Intelephense 1.6.3
I think this is happening because intelephense considers global $var1
an import and $var = 1
the declaration. The phpdoc is attached to the declaration so this appears to be working as expected.
Thanks for your reply.
In our case, we do use global $var1
as a declaration of sorts. See the following made-up example:
<?php
/**
* GLOBALS.php
* all our globals are here....
*/
/** @var bool $stateIsProduction description goes here */
global $stateIsProduction;
/** @var string $locationEmployeePhotos description goes here */
global $locationEmployeePhotos;
/** @var string $locationSomethingOrOther description goes here */
global $locationSomethingOrOther;
if ($condition){
$stateIsProduction = true; // Yay! Production!
}else{
$stateIsProduction = false; // :( Just testing...
}
if ($stateIsProduction){
$locationEmployeePhotos = "/a/path/of/sorts";
}else{
$locationEmployeePhotos = "A:\path\of\sorts\also";
}
if ($stateIsProduction){
$locationSomethingOrOther = "/another/path/of/sorts";
}
?>
<?php
/**
* page.php
* do some work....
*/
include_once("GLOBALS.php");
if (isset($locationSomethingOrOther)){
//do some work if set....
}
?>
In the case where $stateIsProduction
is false
, the only place where $locationSomethingOrOther
is declared is in the global statement at the top of the file. It is not assigned a value (and our code depends on it not being assigned a value, which is a perfectly valid semantic in PHP).
Of course we could add the PHPDoc to the assignments inside the if statements, but that is very messy and reduces the readability of the code.
What happens if you assign a value immediately?
# GLOBALS.php
/** @var bool $stateIsProduction description goes here */
global bool $stateIsProduction = false; // Initial assignment here
if (true) {
$stateIsProduction = true;
}
We have code that depends on whether it is set or not, as I mentioned above.