Being 90 % a C# developer, I do love the way ReSharper analyzes my code in the background and immediately gives inline hints and warnings right in my code editor.

Today I came across a tool called "PHPStan" that seems to be a command line tool that analyzes PHP code for errors/issues/warning.

Suggestion

My suggestion is to include PHPStan (or other similar tools that might exist) into PHP Tools for Visual Studio and build a decent inline UI around it, just like ReSharper does for C# code.

    Thanks, Jakub,

    I'm aware of some suggestions and the like when working with PHP Tools. I didn't know that this is also the same as PHPStan.

    In comparison to ReSharper, there are way fewer hints/suggestions, so I thought PHPStan would bring more than you already have included, but probably more than you already do is not possible.

    Sorry for my ignorance! 😕

    by contraries, it's perfect feedback!

    You are probably right that we have fewer suggestions than PHPStan. We're working on more.

    Integrating a 3rd party tool would be possible as well. We'll look at the other options.

    Here is the rough list of checks that PHPStan does:

    https://phpstan.org/user-guide/rule-levels

    PHP Tools are performing most of the type checks, but there are probably specific and more strict cases, that are not checked. (I know we don't have the list of our check anywhere - working on it)

    Is there anything you'd find helpful to see in PHP Tools now?

    I'm not that familiar with PHP, but in contrast to C#, I really miss that PHP Tools is not warning me about accessing non-existing members.

    Like in the following:

    class Test
    {
        public string $Name;
    }
    
    $test = new Test();
    $test->NonExisting = 10;

    Above, PHP Tools is not warning me about the NonExisting member, despite that I do habe a declare(strict_types=1); directive in the beginning of that very PHP file.

    In contrast, PHP Tools do warn me when calling a non-defined method, by underlining them with green waves:

    $test->CallNonExisting();

    So a big wish would be to also warn me about accessing non-existing properties.

    Seems strict_types=1 only affects coercing scalar types (string >> float >> int >> bool). It has nothing to do with dynamic class properties.

    I'll keep checking if there isn't a directive that would affect that. Or any other commonly used setting. Otherwise, the use of dynamic properties is getting restricted in PHP 8.2.

    If I should switch to 8.2 to fix this, I'm happy to do so.

      UweKeim just trying to find a way how to configure/enable/disable this diagnostic :) so far, it seems it's safe to report any unknown property use unless there is __get() magic method.

      JakubMisek how about allowing the user to configure this by adding special control comments to a class (or attributes) like eg:

      /** phptools:strict-properties=true */
      class MyClass
      {
          …

      Thank you so much, Jakub!

      I've just installed and tried it and it seems to simply work out-of-the-box.

      I've searched through the settings/options of PHP Tools in the Tools → Options dialog but found none regarding this feature that visualizes unknown properties.

      Are there any options or PHPDoc tags, or does it "simply work"?

      Thanks again for making my big wish come true 😊

      thanks for trying it so quickly!

      right, there is no configuration (except for various options on how to disable this diagnostic https://docs.devsense.com/en/vs/code%20validation/configuration) :)

      • unknown properties are reported (unless there is the magic __get() method)
      • a quick fix is provided if the unknown property is similar to an existing property
      • strict_types=1 is respected - this affects numeric type conversions (bool <-> int <-> float <-> string)
      12 days later

      I now have a case like this:

      class MyClass
      {
          public function foo()
          {
              $this->nonExisting = true;
          }
      }

      In the above, it correctly underlines nonExisting.

      Consider this case:

      class MyClass
      {
          public function foo()
          {
              $this->nonExisting = true;
          }
      
          public function __get(string $name)
          {
              return null;
          }
      }

      Now, as you described in your solution, the nonExisting is not underlined anymore.

      Still, I would consider this to be something that PHP Tools should report as an error and underline.

      Reason is that I do an assignment to the variable (i.e. no read) and I do not provide a __set magic method.

      Is it possible for your engine to detect and report those cases, please?

      It is possible, and it makes sense to do so. We'll take a look on that and I'll keep you informed in this thread,

      Thank you!

      8 days later

      Implemented respecting __get and __set - this will get pre-released within upcoming days :-)

      5 months later

      JakubMisek Is it possible to get missing property warning even if the __get magic method exists? I would like to define all existing properties via @property [type] [name] even if the __get method exists and suppress the warning for the classes that I choose.

        TauriT maybe .. if there is some @property tag, then missing properties should be checked even if there is the __get magic method.

        We'd like to avoid falsy warnings for the other users and common composer packages.