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.

4 comments

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

    $row = new static();
    $row->fromJson($json);
    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.

0

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

0

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?

0

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.

0

Please sign in to leave a comment.