amow amow - 9 months ago 104
PHP Question

PhpStorm static method code completion

I use Laravel ORM in my php project and I use a lot of dynamic where in my code. E.g.


When I use PhpStorm 2016.1 (I think) I can add PHPDoc string to class
to have the code completion with
and the following
by doing the following:

* class UserModel
* @method static $this whereName($val)
* @method static $this whereGender($val)
class UserModel {

But after I upgrade to the newest version of PhpStorm 2016.2.2. the second method
will not appear in the code completion list. On JetBrains website I found the 2016.2's new feature

static methods are filtered out from completion lists.

My question is: is there a way to make PhpStorm give the completion
after the


Completion has to be invoked twice to get static methods.

Answer Source


To see the completion, after you type ->, you have to press CTRL + SPACE to see the complete completion list with the static methods. If you are on a mac and it conflicts with your language toggle, change the key combo at:

Main Menu->Code->Completion->Basic

While there is a real use case for this, calling a method static/non-static is not common, hence phpstorm dropped it, as mentioned it here:

The next completion change was to remove static methods from the completion list when completion is invoked in the context of $this->. This change happened as a result of a ticket opened by a user a few years ago. Calling static methods using $this-> is an entirely valid use case but is not that widely used in PHP. While this seemed like a good idea at the time, it’s had the unintended consequences of making writing assertions in PHPUnit a little more painful.

So regardless how you write the phpdoc, phpstorm will not show the static methods as instance methods on the "first invocation". You will need to manually invoke it again (using CTRL+Space) to see it. So this is what the "second invocation" means.