Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过列表<;类别>$PHP中的obj方法/启用类型暗示_Php_Oop_Methods_Intellij Idea - Fatal编程技术网

通过列表<;类别>$PHP中的obj方法/启用类型暗示

通过列表<;类别>$PHP中的obj方法/启用类型暗示,php,oop,methods,intellij-idea,Php,Oop,Methods,Intellij Idea,这是我的方法签名: protected function updateFeeComponent(\FeeComponent $FeeList, $shipment_id, $item_id) { foreach($FeeList as $fee) { //other stuff } } 我称之为: $this->updateFeeComponent($shipmentFeeList,$event_id,$item_id); 其中,$shipment

这是我的方法签名:

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 ItemFeeList

如何将自定义对象列表作为参数传递给函数

编辑:

我正在使用PHPStorm V-9,并且正在集成 要启用类型hint/Intellicode/Available method list(无论您如何命名),我需要提到
变量
类型。我陷入了这个问题。我知道
List
在PHP中是不可用的,但是我们经常说
List
而不是
Array
,因为逻辑是相同的,存储容易访问的多个项(尽管实现和技术不同)

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


我既不是英语母语,也不像这里的大多数人那样是专家。因此,我邀请大家以其他人可以从这个问题中得到答案的方式编辑这个问题。据我所知,你能得到的最接近你想要的东西是:

/**
 * @param FeeComponent[] $FeeList
 */
protected function updateFeeComponent(array $FeeList) {
    // ...
}
其中,将
$FeeList
作为
FeeComponent
的数组,并使用指定所需类型作为
数组

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

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

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

/**
 * @param FeeComponent[] $FeeList
 */
protected function updateFeeComponent(array $FeeList) {
    // ...
}
其中,将
$FeeList
作为
FeeComponent
的数组,并使用指定所需类型作为
数组

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

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

PHP什么时候有了像
List
这样的模板类型?对不起,@var List ItemFeeList,这就是变量类型isPHP没有列表的地方。它有数组,但它们不是类型化的。这是一个
phpdoc
注释吗?我在@Barmar的
phpDocumentor
文档中没有看到类似的内容对不起,我错过了这些注释,我正试图自己修复它。你是对的,PHP什么时候有
List
这样的模板类型了?对不起,@var List ItemFeeList,这就是变量类型isPHP没有列表的地方。它有数组,但它们不是类型化的。这是
phpdoc
注释吗?我在@Barmar的
phpDocumentor
文档中没有看到类似的注释对不起,我错过了这些注释,我正试图自己修复它..你是对的感谢十亿兄弟,第一条注释非常令人沮丧,所以我为这个列表对象创建了一个类成员,设置值并调用函数,你的方法绝对非常简单…再次感谢,谢谢,我承认我的问题没有被清楚地问到…所以投票决定关闭它:P@ZaffarSaffee这可能不是非常清楚,但我认为这是一个有价值的问题,特别是稍微调整一下。我会要求你重新编写或编辑它,以便任何其他发现问题的人都可以查阅它。感谢十亿兄弟,第一条评论非常令人沮丧,所以我为这个列表对象创建了一个类成员,设置了值并调用了函数,你的方法肯定是,非常简单…再次感谢,我承认我的问题没有被清楚地问到…所以投票决定结束它:P@ZaffarSaffee它可能不是非常清楚,但我认为这是一个有价值的问题,特别是有一点调整。我会要求您重新编写或编辑它,以便任何其他发现问题的人都可以查阅它。。