Activerecord.find() Typehint Problem

I’m using the latest version of PhpStorm on Windows 8.1, but for some reason it doesn’t recognize the return type of the ActiveRecord’s find() method:

Sample code from the guide:

class BlogController extends Controller


    public function actionUpdate($id)


        $post = Post::find($id);

        if (!$post) {

            throw new NotFoundHttpException;


        if (\Yii::$app->request->isPost) {


            if ($post->save()) {

                return $this->redirect(['view', 'id' => $post->id]);



        return $this->render('update', ['post' => $post]);



Yii2 BaseActiveRecord.php line 105:

* @return ActiveQuery|static|null

If I ctrl+click on $post->load, then I got an error "Can not find declaration to go to".

But if I change the return type to just "static", then I can navigate to the load() method and other Post class methods.

I wonder if I’m the only one who has this issue. Currently I don’t have an opportunity to test it on another machines.

PhpStorm 7.1.3 build 133.925. Windows 8.1. master of Yii2.

Autocomplete for your case doens’t work since it can return both query and model instance and it seems IDE prefers query.

It works in case of ::find()->one(), but not for ::find(pk) or ::find(pk)->one(). The last one just throws an error. I really wouldn’t like to return to /** @var User $user **/ comments :(

Well, I see no way to make it possible without splitting find() and find(args) into two separate methods.

I guess it’s too complex task for IDE to know the returned type by looking at method arguments. Good old findByPk() would come handy there :)

Well, it’s still not too late to create an issue at github and adjust API a bit ;)

Unfortunately my issue was closed within 5 minutes :D

Do Yii developers prefer notepad++? ;) Or it’s only the PhpStorm issue?

It probably can be solved by PhpStorm team. It’s not possible to solve it at code level w/o method separation that is unwanted by many users.

I hope so, because even the older version of Yii with it’s model() method works better when it comes to typehinting :)