Avoiding 'Method not found in class' for globals

Hi everyone, I am trying to leverage code completion in PHPStorm for classes declared as global.  For example:

global $wpdb;
$result = $wpdb->insert( $table, $values, $format );


In PHPStorm, insert gets highlighted and the error "Method 'insert' not found in class" shows in the tooltip.

I know you can sometimes use PHPDoc tags to enable code completion in PHPStorm, like when using __get() and __set() magic methods with the @property tag.  It would be nice to do something like:

/**
* @class wpdb
**/
global $wpdb;


to enable code completion for the $wpdb variable.  Anyone know of such a thing in PHPStorm?

Thanks in advance.

Eddie

5 comments
Comment actions Permalink

Hi Eddie,

this should probably do the trick:

/**
* @var ClassName $wpdb
*/



Regards,
Bernd
0
Comment actions Permalink

That's awesome, thanks Bernd!

0
Comment actions Permalink

This is, indeed, awesome. Thank you.

Dmitry

0
Comment actions Permalink

Is there a way to do this for a variable stored in the session?

For instance, I have an instance of the class User stored in $_SESSION['user'], and I get the 'Method not found in class' error when I try to call $_SESSION['User']->getName().

This didn't work:

     /**
      * @var User $_SESSION['User']
      */

0
Comment actions Permalink

Hi there,

Is there a way to do this for a variable stored in the session?

No -- it only works with simple variables and will not work with specific array key.

0

Please sign in to leave a comment.