New static construction needs additional PhpDoc for PhpStorm to see it?

I noticed in Symfony2 in code, that there was $request = new static(...);, but later on, when it was used to get public property from it, then public property was highlightend as if it is unreachable. Explanation was following, when I hovered over it: Property noе found in class.

Seems odd and incorrect.


I'm seeing the same issue in the latest EAP release.  Here's a simple code snippet:

    $row = new static();
    return $row;

In this case, fromJson is a method of the current class.  PhpStorm claims the method is unreachable.  Also, typing $row-> doesn't give any autocomplete suggestions at all, so it appears that it isn't able to determine what type is being assigned to the variable.

If I change that first line to:

    $row = new self();

PhpStorm stops complaining.


Well yes, but static and self are different when there is an extended class.


I know that, that's why I'm using static and not self.  However, since the method is part of the parent class, the method should still be valid when the new static() is called from a derived class.  So, shouldn't the code checker recognize the $row variable as an instance of the current class and show the method as reachable?


It should be much simpler. It should analyze it as class without parents. Therefore just eliminate all inherited methods and properties. I hope it will be fixed in coming EAPs, if not, will need to create and issue if it isn't already present.


Please sign in to leave a comment.