Autocomplete of elements added to $this
Hi phpStorm,
I'm hoping someone can help me with auto-complete (or tell me off for doing it wrong).
I'm using phpStorm with CakePHP, and have got the $this-> completing quite well, however I'm finding if I add elements to $this-> phpStorm doesn't suggest them.
public function main()
{
/** @var $this[] $array */
$this->loglevel = 3; // 0-3 (0 = off) - Current Default loglevel
$this->myCustomVar = "Hello";
$this->logfile = false;
.....
}
The phpDoc doesn't seem to make any difference.
If I type $this-> I get suggestions from cake which is great, however inside the main function I was also expecting to see $this->MyCustomVar appearing in the list of suggestions.
Is this because I'm extending $this incorrectly or is there a setting/declaration I'm missing to get phpStorm to correctly detect this?
If I define a standard variable then storm picks this up without an issue, it's extending the this $object it doesn't like (which makes me think I'm coding it badly).
Thanks in advance and sorry if I'm doing something stupid.
请先登录再写评论。
Hi there,
So .. how and where did you define MyCustomVar?
But yes -- class field must be declared in order for IDE to pick it up in $this->MyCustomVar
It could be usual class field declaration
or via @property in PHPDoc for this class -- https://phpdoc.org/docs/latest/references/phpdoc/tags/property.html
>If I define a standard variable then storm picks this up without an issue
You mean -- protected $myAnotherVar; -- this kind of stuff?
> /** @var $this[] $array */
That's incorrect syntax and makes no sense (the $this[] part in particular). What did you try to achieve here?
My bad this wasn't being declared correctly, many thanks for your help