我有一种方法需要int
:
/**
* @param int $someInt
*/
public function methodExpectingInt($someInt)
{
// stuff
}
然而,只有在将对象传入其中时从某处调用时,PhpStorm才会发出警告。
/**
* @return void
*/
public function someMethod()
{
$this->methodExpectingInt(23); // no warning but as an int everything is fine
$this->methodExpectingInt(new \Object()); // gets a warning in phpstorm \o/
$this->methodExpectingInt("this string should issue a warning"); // no warning yet is string
$this->methodExpectingInt(null); // no warning yet is null
$this->methodExpectingInt(2.9); // no warning yet is a float
}
看起来像这样: