bmewburn / vscode-intelephense

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

Option to Toggle typehint: Static Method Calls on Instances #2793

Closed runelanghelle closed 6 months ago

runelanghelle commented 7 months ago

Hello @bmewburn,

First off, I want to express my sincere appreciation for your work on the Intelephense plugin for VSCode. It has significantly enhanced my development workflow!

TL;DR: Proposing an option within Intelephense settings to toggle typehints for static method calls on instances. This aims to support best coding practices by allowing users to choose whether to enable or disable typehints for this specific behavior, enhancing readability and maintaining coding standards.

I've noticed that the plugin currently supports and provides typehints for invoking static methods using class instances (e.g., $instance->staticMethod();). While PHP technically allows this behavior, it is generally considered bad practice for several reasons:

  1. Clarity and Readability: Static methods are intended to be called on the class itself rather than an instance of the class. Allowing instance calls for static methods can lead to confusion regarding whether a method is static or instance-specific, particularly for newcomers or in large codebases.

    Example of recommended practice:

    ClassName::staticMethod(); // Clearly indicates it's a static method

2.Consistency: Encouraging the principle that static methods should be invoked on the class itself promotes a consistent coding style across the project, making the codebase easier to understand and maintain.

3.Future Proofing: Given PHP's flexibility might evolve or stricter static analysis tools might flag this as an issue, adhering to this practice could mitigate potential refactoring challenges.

Considering these points, I propose introducing an option within the Intelephense settings to make this behavior optional. This would allow users who adhere to strict coding standards to disable typehints for static method calls on instances, while others who are unaffected can continue using the feature without change.

Thank you for considering this feature request. Your dedication to developing and maintaining Intelephense is greatly appreciated by the developer community.

Best regards, Rune

bmewburn commented 6 months ago

tracking in #2538