How to tell PhpStorm class variable type


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.    
    //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?


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

might be this is the yet unresolved issue that your wanting:

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.

Comment actions Permalink

Hi Danack,

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

/** @var mysqli_stmt */

private var $statement;

Comment actions Permalink

Thanks - that works!


Please sign in to leave a comment.