Skip to content

variables - unused and undefined #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
felixfbecker opened this issue May 9, 2017 · 9 comments
Open

variables - unused and undefined #374

felixfbecker opened this issue May 9, 2017 · 9 comments

Comments

@felixfbecker
Copy link
Owner

From @manwe-pl on May 9, 2017 13:27

Hi. Thanks for the extension. Two ideas from IntelliJ that you might consider:

  • highlighting unused variables (declared but never used after that),
  • highlighting undeclared variables, that are used (like if(… = $foo) without $foo = …).

Copied from original issue: felixfbecker/vscode-php-intellisense#120

@str
Copy link

str commented Aug 8, 2017

  • highlighting unused namespaces

@Suver1
Copy link

Suver1 commented Oct 26, 2017

This feature is the reason why i still use PhpStorm instead VSCode for PHP.

@felixfbecker
Copy link
Owner Author

Please don't +1 issues. It clutters the thread without adding value to the discussion and spams maintainers with notifications. Use GitHub reactions to upvote features.
image

@TysonAndre
Copy link
Contributor

TysonAndre commented Mar 23, 2018

highlighting undeclared variables, that are used (like if(… = $foo) without $foo = …).

This will have a small number of false positives for parameter references, which would become much smaller if type checking and possibly control flow analysis were introduced (E.g. $closure($arg, $outputReference); would warn about $outputReference being undeclared. Another example: $x would be undefined for if (cond()) { $x = 2; if(CONST) {return;} else {throw new Exception('message');} } call_function_using($x);).)

highlighting unused variables (declared but never used after that),

There's an open source plugin for a different project. That plugin performs unused variable detection, and only unused variable detection (Has some issues understanding references, loops and complex nested expressions right now, and is somewhat messy). It's a completely different AST format. An easy to implement (but slow) solution would be to convert the tolerant-php-parser AST to the other AST type that the mentioned plugin expects. A better solution would be to reimplement based on that design, targeting tolerant-php-parser. (The plugin is Apache licensed, the project the plugin is for is MIT licensed)

This feature (unused and undefined detection) is the reason why i still use PhpStorm instead VSCode for PHP.

Until this issue is closed, this can be worked around by running both felixfbecker/php-language-server and another language server with the desired diagnostics, and disabling any redundant/conflicting features such as syntax error detection.

@JonGarbayo
Copy link

Any news on this feature :) ?

@felixfbecker
Copy link
Owner Author

@JonGarbayo if there were news they would be posted here. Please use the subscribe feature, no need for polling ;)

@JonGarbayo
Copy link

Sorry, it was just in case you forgot ;)

@felixfbecker
Copy link
Owner Author

This feature won't be implemented unless someone submits a PR, so there is no need to remind me personally ;)

@oscar-gardiazabal
Copy link

This feature is the reason why i still use PhpStorm instead VSCode for PHP.

https://github.com/sirbrillig/phpcs-variable-analysis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants