bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.57k stars 93 forks source link

$http_response_header is incorrectly reported as defined out of scope #2820

Closed L1Q closed 1 week ago

L1Q commented 3 months ago

Predefined variable $http_response_header is only autopopulated in local scope where HTTP wrapper was used, e.g. after file_get_contents.

Intelephese incorrectly reports $http_response_header as always defined in any scope, regardless of HTTP wrapper usage earlier in local scope.

Code from php.net:

function get_contents() {
  file_get_contents("http://example.com");
  var_dump($http_response_header); // variable is populated in the local scope
}
get_contents();
var_dump($http_response_header); // a call to get_contents() does not populate the variable outside the function scope

Here, only the first $http_response_header should be reported as defined, but both are.

pjylkka commented 2 months ago

On my computer, on global scope any variable seems not to be marked as unknown. I thought i've just had some setting wrong that I did not know about;

image

bmewburn commented 1 month ago

In the next release the type of $http_response_header will be changed to unset|array. There's no plans to try and accurately determine when this variable becomes defined as it looks like it may be removed in future versions of PHP. https://wiki.php.net/rfc/http-last-response-headers