該公司保持其代碼中的PHP錯誤被抑制,但我turned it on看到爲什麼我的東西不工作。isset()和empty()似乎無法修復「未定義索引」通知
但是,現在我收到數百個Undefined index
消息,我想關閉以便我可以從我的代碼中找到消息。
這裏,讓許多錯誤一個特定塊:
final public function getAttribute($name) {
$value = '';
if(is_array($this->attributes[$name]) === false) { // Notice: Undefined index: name
$value = trim($this->attributes[$name]);
} else {
$value = trim(implode(' ', $this->attributes[$name]));
}
return $value;
}
爲了消除這些通知,我也跟着後Why check both isset() and !empty()把它寫這樣的:
final public function getAttribute($name='') {
if (!isset($name) || empty($name)) {
return '';
}
$value = '';
if(is_array($this->attributes[$name]) === false) { // Notice: Undefined index: name
$value = trim($this->attributes[$name]);
} else {
$value = trim(implode(' ', $this->attributes[$name]));
}
return $value;
}
我仍然得到通知,和在同一個地方。
我如何修復的代碼,以便它不會創建此條件?
你的PHP大師們真的很厲害! – jp2code