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
Please sign in to leave a comment.
Hi Eddie,
this should probably do the trick:
Regards,
Bernd
That's awesome, thanks Bernd!
This is, indeed, awesome. Thank you.
Dmitry
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:
Hi there,
No -- it only works with simple variables and will not work with specific array key.