Declare class property with phpdoc

Hey,

I have some classes where I use "magic" method __get to perform hot plugs on properties.
The pain here is that when I use those properties, ie $myObject->hotPluggedStuff, they are detected by phpstorm as wrong properties.

I tried to use phpdoc to "declare" them, like that :


class ToolBox {

    /** @var $twig Twig_Environment */



But it doesn't seem to work.

Is there any way to avoid those false warning ?

Thanks guys.
14 comments
Comment actions Permalink

Nice, I didn't know this tag.
But unfortunately, phpstorm doesn't seem to know it either...
Warning still there.

0
Comment actions Permalink

PhpStorm definitely does know about it.
Are you sure you are using annotation properly? Its a class-level annotation...

0
Comment actions Permalink

You're right, I misplaced it...

Problem solved, thanks Dmitriy & Alexey !

0
Comment actions Permalink

I know this is an old thread, but PHPstorm isn't auto completing @properties that I define.

 

Can you post an example that worked ?

0
Comment actions Permalink

Sure, here is one.

Remember, it's a class level tag, so it should be placed *before* class declaration.

/**
* @property $listeErreurs array
* @property $competenceList array
*/
class opd
{
...
0
Comment actions Permalink

Thanks, I tried that but they aren't getting picked up by auto complete

2
Comment actions Permalink

Strange, I just tried and it works perfectly.

Your variable needs to be explicitly from that class too, something like :

/** @var opd $opd */
$opd->competenceList;

This way I've got auto completion on my properties.

0
Comment actions Permalink

 

There is another weird thing.

When I paste PHPDoc from somewhere, it works. But when I type the same PHPDoc by hand, it won't.

0
Comment actions Permalink

Can you provide an example?

 

0
Comment actions Permalink

@property definition on class level ($status_id typed by hand, $listeErreurs copied from this post, $test1 copied from $listeErruers, $test2 typed by hand):

Auto complete shows only $listeErruers and $test1, both copied:




0
Comment actions Permalink

Did you try to run File > Invalidate Caches\Restart > Invalidate and Restart? Is it the same after that action?

0
Comment actions Permalink

Tried "Invalidate and Restart", it is the same.

0

Please sign in to leave a comment.