Whats is wrong with field accessedf via magic method


I get the message field accessedf via magic method,

What is wrong with this method?


En what is the right way to do it ?

1 comment
Comment actions Permalink

There's nothing wrong. But you're running an inspection to determine whether you're using properties that have not been defined, an inspection that's useful because it can detect typos, e.g.:

class Foo


public $blah;


(new Foo())->bla = 3.14;

If the method is defined via a magic method then PhpStorm warns that it can't reliably tell you if the property name is correct or not.

What I normally do (this may or may not be viable depending on your use case) is to declare it with annotations. That has the added benefit of making the property or method show up among auto-completion suggestions:



 * @property-read \PDO $database

 * @property int $blah


class Foo



Otherwise, just ignore, silence or disable the inspection.


Please sign in to leave a comment.