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.

0

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

public/protected/private $myCustomVar;

or via @property in PHPDoc for this class -- https://phpdoc.org/docs/latest/references/phpdoc/tags/property.html

/**
 * My Class (bla-bla)
 *
 * @property string $MyCustomVar Bla-bla description
 */
class MyClass extends AnotherClass
{
...

>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?

1

My bad this wasn't being declared correctly, many thanks for your help

0

请先登录再写评论。