PHP Traversable type hint

前端 未结 4 1617
-上瘾入骨i
-上瘾入骨i 2021-01-03 23:15

I have a relatively simple function which uses a foreach

function foo($t) {
     $result;
     foreach($t as $val) {
         $result = dosometh         


        
4条回答
  •  孤街浪徒
    2021-01-03 23:57

    PHP 7.1 introduces the iterable type declaration for this purpose, which accepts both arrays and instances of \Traversable.

    In previous versions, you'll have to omit the type declaration.

提交回复
热议问题