Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get rid of magic method warning

Tags:

phpstorm

Is there any way to get rid of this annoying PhpStorm warning:

Member has private access, but class has magic method __get

Thank you!

like image 722
Ksamp Avatar asked Jul 01 '16 20:07

Ksamp


People also ask

What is the purpose of the magic method?

Magic methods are special methods in python that have double underscores (dunder) on both sides of the method name. Magic methods are predominantly used for operator overloading.

What is __ get?

__get() is utilized for reading data from inaccessible properties.

What is __ invoke in PHP?

The __invoke method is a way that PHP can accommodate pseudo-first-class functions. The __invoke method can be used to pass a class that can act as a closure or a continuation, or simply as a function that you can pass around. A lot of functional programming relies on first class functions.

What is PHP magic?

Magic methods in PHP are special methods that are aimed to perform certain tasks. These methods are named with double underscore (__) as prefix. All these function names are reserved and can't be used for any purpose other than associated magical functionality. Magical method in a class must be declared public.


1 Answers

You can turn off warnings for magically accessing properties in the following way:

  1. Go to File -> Settings -> Editor -> Inspections
  2. Go to PHP -> Undefined -> Undefined field
  3. Uncheck the box for "Notify about access to a field via magic method"

I am not entirely sure if this will also hide the warning in your case, for accessing private members. If not, you could also use the @property PHPDoc tag to describe which fields are accessible through your magic __get method.

Check this page for more information

like image 199
chocochaos Avatar answered Oct 21 '22 13:10

chocochaos