PHPSForm使用Laravel声明错误的方法
我正在使用PHPStorm8.0.3(2月12日构建)构建一个Laravel4.2应用程序。我也在用Barry Heuvel的 我在声明与雄辩方法同名的方法时出错。更清楚地说,下面是一些示例代码:PHPSForm使用Laravel声明错误的方法,php,laravel,eloquent,phpstorm,Php,Laravel,Eloquent,Phpstorm,我正在使用PHPStorm8.0.3(2月12日构建)构建一个Laravel4.2应用程序。我也在用Barry Heuvel的 我在声明与雄辩方法同名的方法时出错。更清楚地说,下面是一些示例代码: class SomeModel extends Eloquent{} class OtherClass { public function update($first, $second, $third){ //do some stuff return tru
class SomeModel extends Eloquent{}
class OtherClass {
public function update($first, $second, $third){
//do some stuff
return true;
}
public function check(){
$item = SomeModel::findOrFail('1');
$item->update([
'name' => 'my name',
'attribute' => 'some attribute'
]);
return "here's the problem!";
}
}
在这段代码中,item->update([…
以红色突出显示,错误消息为Required参数$second missing…。如果我在那段代码上使用“go to declaration”,而不是去Elount的update方法的声明,它将转到顶部声明的方法
还有其他人遇到这个错误吗?你找到解决方法了吗?我不确定这是PhpStorm、我的代码还是ide帮助程序的问题
谢谢
编辑
我想我找到了问题的根源,多亏了LazyOne的评论。
在findOrFail的声明中,PHPDoc读取:
@return\illumb\Support\Collection | static
。当更改为“@return\illumb\Support\Collection\static”或干脆不使用static时,不会显示错误。PHPStorm读取docstring是否正确,或者格式是否不正确?IDE似乎失败了检测正确类型的$item
最有可能是由于SomeModel::findOrFail()的方式
起作用/声明——它认为它是其他类的一个实例。建议的解决方案是通过PHPDoc注释给出适当的类型提示,例如/**@var SomeModel$item*/
在$item=…
行之前。我自己不是Laravel用户。谢谢!这是一个很好的补丁,它修复了错误。但它仍然很烦人ng必须在每个FindDorFail上编写PHPDoc,因为我有很多。希望有人有一个全局解决方案。再次感谢!为PhpStorm
使用提供phpCode
。正如我在消息开头所写的,我正在使用ide帮助程序。这与PHPDoc中的@return声明有关。