global $object = undefined method warning

I've run into a slight issue with wordpress plugins, where I use the global database object ($wpdb) for queries.
it works fine, but PHPStorm highlights all methods (e.g. $wpdb->get_var() ) as undefined and also does not offer code completion for the methods or properties.
jumping to the declaration of $wpdb (cmd-b), points to the wrong location: a file (/wp-admin/includes/schema.php) where $wpdb is included as global, but not where the object is created or the class is defined (/wp-includes/wp-db.php).

is there something I can do to fix this behavior, or is this an issue for the tracker?

any help appreciated.

Comment actions Permalink

just in case anyone else stumbles across this thread,
adding the following to the plugin file, does the job:

if(false) {
  $wpdb = new wpdb("","","","");

now the inspections and code completion work as beautiful as ever.

Comment actions Permalink

Nonono, you should use next phpdoc instead:

/** @var $wpdb wpdb */
global $wpdb;

Comment actions Permalink

thats far better.
thank you very much.


Please sign in to leave a comment.