Declare class property with phpdoc Follow
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.
Please sign in to leave a comment.
You should use @property (http://manual.phpdoc.org/HTMLSmartyConverter/PHP/phpDocumentor/tutorial_tags.property.pkg.html) tag to document your magic properties.
Nice, I didn't know this tag.
But unfortunately, phpstorm doesn't seem to know it either...
Warning still there.
PhpStorm definitely does know about it.
Are you sure you are using annotation properly? Its a class-level annotation...
You're right, I misplaced it...
Problem solved, thanks Dmitriy & Alexey !
I know this is an old thread, but PHPstorm isn't auto completing @properties that I define.
Can you post an example that worked ?
Sure, here is one.
Remember, it's a class level tag, so it should be placed *before* class declaration.
Thanks, I tried that but they aren't getting picked up by auto complete
Strange, I just tried and it works perfectly.
Your variable needs to be explicitly from that class too, something like :
This way I've got auto completion on my properties.
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.
Can you provide an example?
@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:
Did you try to run File > Invalidate Caches\Restart > Invalidate and Restart? Is it the same after that action?
Tried "Invalidate and Restart", it is the same.
That seems to be https://youtrack.jetbrains.com/issue/WI-23988