我能做些什么来让 PhpStorm (2016.1) 识别"new X()"
范围之外的类型吗?
SomeClass.php:
class SomeClass
{
public function DoMagic()
{
echo "doing magic";
}
}
DummyClass.php:
class DummyClass
{
protected $mParamsList;
function __construct()
{
$this->mParamsList = array();
}
public function InitParamsList()
{
$this->mParamsList[] = new SomeClass();
}
public function GetParamsList()
{
return $this->mParamsList;
}
}
UserClass.php - 没有建议:
class UserClass
{
public function DoMagic()
{
$dummy2 = new DummyClass();
$params = $dummy2->GetParamsList();
foreach ($params as $param)
{
$param-> * nothing happens *
}
}
}
?>
我发现添加这个 hack 是可行的,但是使用它变得令人沮丧:
if (false) { $param = new SomeClass(); }
所以完整的工作示例是:
class UserClass
{
public function DoMagic()
{
$dummy = new DummyClass();
$params = $dummy->GetParamsList();
foreach ($params as $param)
{
if (false)
{
$param = new SomeClass();
}
$param-> * suggestions pop up *
}
}
}