Doctrine forAllでmust be of type ○○, int given,が出る
サンプルコード(エラーがでる)
$collection=new ArrayCollection(["a","b","c"]);
if($collection->forAll(function(Hoge $hoge){
//何か処理
}
エラー内容
Argument #1 ($hoge) must be of type Hoge, int given
背景
$collection=new ArrayCollection(["a","b","c"]);
if($collection->forAll(function(Hoge $hoge){
//何か処理
}
Argument #1 ($hoge) must be of type Hoge, int given
背景
filterやmapなどと違い、forAllは与えられた無名関数に(key,value)の組を与えます。
ドキュメント:https://www.doctrine-project.org/projects/doctrine-collections/en/1.6/index.html#forall
修正
$collection=new ArrayCollection(["a","b","c"]);
if($collection->forAll(function(int $key,Hoge $hoge){
//何か処理
}
あとがき
$collection=new ArrayCollection(["a","b","c"]);
if($collection->forAll(function(int $key,Hoge $hoge){
//何か処理
}
filterとかから書き換えたときに陥りがちなエラーで、ドキュメントを見れば一発ですが意外と気づかないもんですね。
Author And Source
この問題について(Doctrine forAllでmust be of type ○○, int given,が出る), 我々は、より多くの情報をここで見つけました https://qiita.com/NotWhiteButHundred/items/aa08b1715448824ecbe7著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .