How to tell PhpStorm class variable type

Hi,

Sometimes I wrap the built-in PHP classes with one of my own e.g.

class StatementWrapper{
 
 
     private var $statement; //This will always be a mysqli_stmt object




     function executeWrapped(){
    
       //do some logging.    
    $this->statement->execute();
    //do some other logging.    
     }
}


PhpStorm shows an error on the execute() line saying "Method 'execute' not found in class."



How do PhpStorm that the variable '$statement' will always be a mysqli_stmt object? Alternatively is there a way to make it not show that error for things that are only defined as vars?

cheers
Dan

btw Apologies if this is asked lots of times before - I couldn't find the answer easily.
3 comments
Comment actions Permalink

might be this is the yet unresolved issue that your wanting:
http://youtrack.jetbrains.com/issue/WI-6027

its not supported yet as far as i know and whenever i run into chained methods while debugging with xdebug, things get real confusing real fast.  Its scheduled for the next release though :)

Vote for it if it fits your situation.

0
Comment actions Permalink

Hi Danack,

Try adding PHPDoc block comment with type hint, like this:

/** @var mysqli_stmt */

private var $statement;

0
Comment actions Permalink

Thanks - that works!

0

Please sign in to leave a comment.