我對magento使用的主題是「Love Fashion」,但是這僅僅是爲了解如果有人遇到過與此主題相同的問題之前的信息。調試一個未定義的變量,Magento PHP
我收到以下錯誤Notice: Undefined variable: deal
。兩行上,50和61發生了錯誤 - 但是該錯誤兩次上顯示出線路50例如:
Notice: Undefined variable: deal on line 50
Notice: Undefined variable: deal on line 50
Notice: Undefined variable: deal on line 61
這發生以下代碼(起始於線49,線67上結束):
public function addFilter($filterName,$filtervalue,$condition='='){
if ($deal instanceof Sm_Deal_Model_Deal){
$deal = $deal->getId();
}
if (!$this->_joinedFields){
$this->joinFields();
}
$this->getSelect()->where('deal.'.$filterName.' '.$condition.' ?', $filtervalue);
return $this;
}
public function OrderbyAdd($orderName,$ordervalue){
if ($deal instanceof Sm_Deal_Model_Deal){
$deal = $deal->getId();
}
$this->getSelect()->order('deal.'.$orderName.' '.$ordervalue);
return $this;
}
所以我的問題是,我如何解決在這種情況下未定義的變量?
例如,我用下面的代碼早在同一文件中,但是這並沒有給任何錯誤:(開始於第26行,47行結束)
public function addDealFilter($deal){
if ($deal instanceof Sm_Deal_Model_Deal){
$deal = $deal->getId();
}
if (!$this->_joinedFields){
$this->joinFields();
}
$this->getSelect()->where('related.deal_id = ?', $deal);
return $this;
}
public function joinFieldsdeal(){
$this->getSelect()->join(
array('deal' => $this->getTable('deal/deal')),
'deal.entity_id = related.deal_id',
array('deal.end_date','deal.start_date','deal.name')
);
$this->_joinedFields = true;
return $this;
}
問題並不是"Reference: What is variable scope, which variables are accessible from where and what are 「undefined variable」 errors?"的重複,因爲這只是解釋了函數的基礎 - 在這裏並不是這樣。
[參考:什麼是變量作用域,哪些變量可以從哪裏訪問,什麼是「未定義變量」錯誤?](http://stackoverflow.com/questions/16959576/reference-what-is-variable -scope-which-variables-are-accessible-from-where-and) – IMSoP
嗨IMSoP - 它可能是同樣的問題,但你鏈接到的問題,只定義了函數的基礎,我已經知道了。我上面列出的代碼,我不明白範圍,因爲這不是我清楚,因爲你連接的範圍。 – Patrick
考慮到在相關答案中解釋的範圍規則,您認爲'$ deal'將來自通知中突出顯示的行嗎? – IMSoP