Define common global variables types as a project setting

I usually add PHPDoc comments to global variables to remove all the code inspection warnings and to get intellisense, but a client a work for is complaining about them and asked me to remove all these comments, as "unneeded".
So I have no choice: I must remove them.

I'm working in a WordPress related project, so there is a set of commonly used global variables. For instance I often use these:

 /** @var $wpdb WPDB */

 global $wpdb;

 /** var $pagenow string */

 global $pagenow;

/** @var $wp_query WP_Query */
 global $wp_query;


I wonder however if I there is in PhpStorm, in Project settings, or somewhere else, a place where I can define them "globally", so I can still get all the advantages of intellisense and no code inspection warnings.

5 comments

Hi there,

I wonder however if I there is in PhpStorm, in Project settings, or somewhere else, a place where I can define them "globally", so I can still get all the advantages of intellisense and no code inspection warnings.

No.

You may try this: create a separate .php file and place it ANYWHERE in the project (e.g. will be available on your computer only). There you declare all such variables with proper PHPDocs -- should work.

0

I don't see how this could work.

Code inspection and intellisense works for the current file.

If I add them in a separate file it will work in this separate file, not in all the other files where I use these variables.

0

I don't see how this could work.

Code inspection and intellisense works for the current file.

If I add them in a separate file it will work in this separate file, not in all the other files where I use these variables.

So .. did you tried what I have suggested ... or you just speculating?


Could you please share your knowledge and explain why this one should not work (while it does work)?
screen01.png

0

How lovely is the tone of your mail.
I don't know if you're an official support guy, or just a forum member, but if you are, then you really have a lot to learn on how to provide professional support.

The tone of my answer was polite and I may have missed to tell that i did try what you've suggested, even if I was felling stupid, as I knew it wouldn't have worked.
But I did try and not mentioning doesn't give you a reason for being so acrid in your answer.

It simply doesn't work.

I've added all my global variables in a test.php file inside the project, adding all the appropriated PHPDoc comments.
Whenever I use the same global variables (besides, they still have to be declared as global in the "real" files, not just in the test.php file), they are still highlighted as undefined.

I hope that having shared my "wisdom" helped you provind that your solution doesn't work.

Goodbye.

0

I'm not not member of JB stuff. But I have realised my words shortly after I typed them and altered my post. My appologies.

In any case: I did a test before writing it .. and it DOES work here (both PhpStorm v6 and v7 EAP). The simple code example shown on screenshot (previous post) also shows that it works.

Here are actual screenshot from wordpress code (v3.6 -- downloaded today; no modifications).
screen01.png

screen02.png
(on 2nd pic I have changed the name of varible to show how it otherwise looks in the code when no proper PHPDoc comment applied).


Another example code, file 1.php

<?php
class Kitten
{
    /**
     * @param string $what Bla Bla ($kitten)
     */
    public function sayIt($what = '')
    {
        echo $what ? $what : "Meow!\n";
    }
}


/** @var Kitten $k */
global $k;


file 2.php

<?php
$k->sayIt('ok');


This example works just fine here as well (tested in v7 EAP build)

0

Please sign in to leave a comment.