使用PHP,是否有函数/方法/方法来检查变量是否包含可以安全地放入foreach构造中的内容?有点像//thesimplecase,wouldprobablyneveruseitthisbluntlyfunctionfoo($things){if(isForEachable($things)){foreach($thingsas$thing){$thing->doSomething();}}else{thrownewException("Can'tforeachovervariable");}}如果您的回答是“设置一个处理程序来捕捉PHP错误”,我们将不胜感激,但我正在寻找其他东西。