Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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,奇怪的“;为foreach“提供的参数无效”;用打字机提示_Php_Arrays_Casting_Arguments - Fatal编程技术网

PHP,奇怪的“;为foreach“提供的参数无效”;用打字机提示

PHP,奇怪的“;为foreach“提供的参数无效”;用打字机提示,php,arrays,casting,arguments,Php,Arrays,Casting,Arguments,我有这样的功能: function fo(array $ids){ foreach($ids as $key => $val) do_something_simple_without_pointers_and_stuff_like_that($key, $val); } 我知道我可以做“is_array check”,但是,当我在函数参数中有类型提示时,怎么可能得到php警告“为foreach()提供的参数无效?”呢?作为数组传递的是什么$id但是如果我传递字符串或null,

我有这样的功能:

function fo(array $ids){
  foreach($ids as $key => $val)
    do_something_simple_without_pointers_and_stuff_like_that($key, $val);
}

我知道我可以做“is_array check”,但是,当我在函数参数中有类型提示时,怎么可能得到php警告“为foreach()提供的参数无效?”呢?

作为数组传递的是什么
$id
但是如果我传递字符串或null,我应该得到“可捕获的致命错误:参数1传递给[ClassName]:\u call()必须是字符串的实例,字符串在[line\u number]行的[php\u file\u name]中给出,“您的数组结构是什么?结构类似于:array('string','string2','string3',…)请提供一个完整的、自包含的示例,它正好再现了这个问题。在您展示的代码片段中,确实不可能得到该警告。