传递列表<;类>$obj到PHP中的一个方法/启用类型提示


passing list <Class> $obj to a mthod in PHP / enabling Type hinting

这是我的方法签名:

protected function updateFeeComponent('FeeComponent $FeeList, $shipment_id, $item_id)
{
    foreach($FeeList as $fee)
    {
       //other stuff
    }
}

我称之为:

$this->updateFeeComponent($shipmentFeeList,$event_id,$item_id);

其中CCD_ 1是CCD_。

如何将LIST of Custom对象作为参数传递给函数?

编辑:

我正在使用PHPStorm V-9,并且正在集成Laravel Amazon mws库要启用类型hint/Intellicode/Available方法列表(无论您将其命名为什么),我需要提到variable类型。我陷入了这个问题。我知道List在PHP中不可用,但我们经常说List而不是Array,因为逻辑有些相同,存储易于访问的多个项目(尽管实现和技术不同)。

所以,我的问题是关于类型暗示,在提出这个问题的那一刻,我承认,我没有想到array而不是List。。。

我既不是土生土长的英国人,也不像这里的大多数人那样是专家。。因此,我邀请每个人编辑这个问题,以使其他人可以从这个问题中获得他的解决方案

据我所知,最接近您想要的东西是:

/**
 * @param FeeComponent[] $FeeList
 */
protected function updateFeeComponent(array $FeeList) {
    // ...
}

使用PHPDoc将$FeeList的类型注释为$shipmentFeeList0的数组,并使用PHP类型提示将所需类型指定为array

在支持读取类似PHPStorm的PHPDoc的IDE中,这将正确地将输入数组中的每个元素视为FeeComponent,并提供有效的提示,例如

foreach ($FeeList as $fee) {
    $fee-> // Be provided with properties and methods of FeeComponent
           // in hints here.
}