I have got a warning in PhpStorm for a common use of static calls. I have:
class Test {
public static function thisIsATest(){
// do stuff
}
}
Then, I have:
$className = 'Test';
$className::thisIsATest();
This is not an error, btw I have this in my PhpStorm:
Is there a way to handle this? At least, is it possible to just hide this warning?
There are some solutions, for this problem:
change to a PHP Version >= 5.3.0
use call_user_func(array('Test','thisIsATest'));
in older PHP versions
change code-inspection-behavior in phpstrom under project settings (also ensure phpstrom has the right PhpVersion set up for your current project)
[Solution] Declare the variable with annotations in phpstrom in the right way!
Like:
<?php
/**
* @var $className Test
*/
$className::thisIsATest();
Now phpstrom know that $className
is a instance of Test
that has a method called thisIsATest
, and no error hint pops up.