Php 警告:为每个()提供的参数无效
在我的站点上获取第113行的错误,不确定为什么会发生这种情况,或者需要做什么来更正代码。请参阅下面的代码片段Php 警告:为每个()提供的参数无效,php,Php,在我的站点上获取第113行的错误,不确定为什么会发生这种情况,或者需要做什么来更正代码。请参阅下面的代码片段 // Return the CDN object by name. // If a section is defined. Only returns the object if it exists in that section // if "Section" is not defined; returns an object if it exists in an
// Return the CDN object by name.
// If a section is defined. Only returns the object if it exists in that section
// if "Section" is not defined; returns an object if it exists in any section.
// Returns FALSE if not found.
public function CDN($name='',$section=''){
if (empty($name)) return FALSE;
else
foreach ($this->CDNS as $CDN){
if (!empty($section)) {
if (stripos($name, $CDN->Name()) !== FALSE && ($CDN->Position() == $section)) return $CDN;
}
else
if (stripos($name, $CDN->Name()) !== FALSE) return $CDN;
}
return FALSE;
}
似乎
$this->CDNS
是空的。你可以这样做:
public function CDN($name='',$section=''){
if (empty($name)) return FALSE;
else
{
if(!empty($this->CDNS))
{
foreach ($this->CDNS as $CDN){
if (!empty($section)) {
if (stripos($name, $CDN->Name()) !== FALSE && ($CDN->Position() == $section)) return $CDN;
}
else
if (stripos($name, $CDN->Name()) !== FALSE) return $CDN;
}
return FALSE;
}
}
}
阵列$this->CDNS为空。感谢您的帮助。如何更正此问题?将某些内容放入其中?在foreach之前添加条件,例如:
if(!empty($this->CDNS)){…
这不是因为$this->CDNS
是空的,而是因为它不是可以迭代的。所以问题是:它是什么?!为什么是这样?为什么它不是像你期望的那样是可写的?不要设置&!empty
;只要!empty
就可以了。是的,你是对的。我已经更新了answer、 感谢您指出错误。也不是因为“[the]数组是空的”,而是因为它不是数组。空数组不会导致错误。@sarkism不客气。别忘了将此标记为答案,它可能会在将来帮助其他人。