32bitfloat
32bitfloat

Reputation: 771

which is the correct PHPdoc for methods of objects which are properties in phpstorm?

I'm new to PHPStorm and I imported an existing project in this IDE. Now I receive many warnings like

Method 'query' not found in class

I read about using PHPDoc-blocks in order to declare the origin of variables which are not defined in the current class, but I cannot get out how I should do it for this situation:

class loginModel extends Model{
  public function checkLogin(){
    [...]
    if($this->db->query($sql)){[...]} //Warning as stated above
    [...]
  }
}

$this->db itself is inheritated from class Model:

class Model{

  protected $db;     

  private function connect(){
    $this->db = new PGSQL();
  }
}

and therefore can access the public PGSQL method named query.
Maybe not that well designed, but how could I solve these messages without downgrading their severity?

Upvotes: 1

Views: 351

Answers (1)

Mike B
Mike B

Reputation: 32145

class Model{

    /**
     * @var PGSQL
     */
    protected $db;

    private function connect(){
        $this->db = new PGSQL();
    }
}

Docblocks work on properties too

Upvotes: 5

Related Questions