这是我的方法签名:
protected function updateFeeComponent(\FeeComponent $FeeList, $shipment_id, $item_id)
{
foreach($FeeList as $fee)
{
//other stuff
}
}我称之为:
$this->updateFeeComponent($shipmentFeeList,$event_id,$item_id);$shipmentFeeList是@var List<FeeComponent> ItemFeeList的地方。
如何将自定义对象列表作为参数传递给函数?
编辑:
我使用的是PHPStorm V-9,并且正在集成Laravel-Amazon-mws图书馆来启用类型提示/ Intellicode / Available方法列表(不管您怎么命名),我需要提到variable类型。我陷入了这个问题。我知道List在PHP中是不可用的,但是我们经常说List而不是Array,因为逻辑有点相同,存储容易访问的多个项(尽管实现和技术不同)。
所以,我的问题是关于类型暗示,在问这个问题的时候,我承认,我没有想到array而不是List。
我既不是英语母语,也不是here..so的专家,我邀请大家编辑这个问题,就像其他人可以从这个问题中得到他的答案一样。
发布于 2016-05-12 00:45:42
据我所知,最接近你想要的是:
/**
* @param FeeComponent[] $FeeList
*/
protected function updateFeeComponent(array $FeeList) {
// ...
}其中将用PHPDoc注释类型 for $FeeList作为FeeComponent数组,并使用PHP类型提示将所需的类型指定为array。
在支持读取PHPDoc (如PHPStorm )的IDE中,这将正确地将输入数组中的每个元素视为FeeComponent,并提供有效的提示。
foreach ($FeeList as $fee) {
$fee-> // Be provided with properties and methods of FeeComponent
// in hints here.
}https://stackoverflow.com/questions/37175319
复制相似问题