PHP Class properties not recognized

As of newest PhpSorm update 2021.2, class properties with phpdoc @property comments are not recognized. Usually class properties are colored in different color.

Maybe it is because now IDE thinks it is two different properties?


Comment actions Permalink

Hi there,

PHPDoc's @property tag is meant for magic (not real / dynamic) fields only (that are getting accessed via __get() / __set() methods)

If you need to typehint your $bar real property then do it using appropriate @var tag:

/** @var string My cool bar property */
public $bar;

P.S. Yes, it's a fix since 2021.2 version.

Comment actions Permalink


So it seems, that I used @property tag incorrectly. It was handy that IDE changed attribute name color and was really easy to spot incorrect attribute names.

Comment actions Permalink

The IDE already tells you about wrong / non-existing properties:


* @property string $meow
class Foo4 {
public string $bark;

$a = new Foo4();
$a->bark = 'yes';
$a->meow = 'nope';
$a->oink = 4;

It will highlight such place with the notice (see the screenshot below).

You can increase the visibility by changing the severity of that inspection to a more noticeable warning (or even an error) level if needed. The style / how noticeable it is depends on your Color Scheme / Theme used.


BTW: If will be accepted then PHP 8.2+ will throw warnings during runtime on such dynamic property access (without __get/__set in place).

Comment actions Permalink

Thanks, I will change inspection severity to error.


Please sign in to leave a comment.