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 ToolsOptions 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.

        JakubMisek Does not seem to work correctly or am I missing something?

          JakubMisek There seem to be even bigger issues regarding @property annotations. It is not recognising basic properties in some cases but I have not managed to pull simplified example out of my main project.

            TauriT Okay looks like i was missing $ from the property name in annotation.

              5 days later

              implemented - undefined property will be reported even there is __get/__set if there are already some @property in doc blocks defined.

              we have also added diagnostic for incorrectly defined @property (with missing property $name)