2013-11-28 21 views
0

真的,真的很抱歉..看來問題出在我用過的KLogger上。我從我的代碼中刪除KLogger,現在它工作得很好。從來沒有想過一個簡單的記錄類會導致問題。無法多次實例化同一班級

這裏是我的PHP類

<?php 
session_start(); 

error_reporting(E_ALL); 
ini_set('display_errors', '1'); 
error_reporting(1); 

class Gamification { 

    private $webAction; 
    private $currentLimit; 
    private $maxLimit; 

    function __construct($getWebAction) {   
     $this->webAction = $getWebAction; 

     include ("config.path.php"); 
     include ($config['BASE_DIR']."/include/KLogger.php"); 
     $log = KLogger::instance($config['BASE_DIR'].'/log/'); 

     $log->logInfo('class.gamification.php: line 21: webAction:'.$getWebAction); 

    } 

    public function getMaxLimit(){ 
     $this->maxLimit = 99; 
     return $this->maxLimit; 
    } 

    public function getCurrentLimit(){ 
     $this->currentLimit = 3; 
     return $this->currentLimit; 
    } 
} 

?> 

,我試圖多次從其他PHP頁面實例,就像這樣:

$gamification = new Gamification("expensesCategory"); 
    $currentLimit = $gamification->getCurrentLimit(); 
    $maxLimit = $gamification->getMaxLimit(); 

    $gamificationInfoExpFixedMonthly = new Gamification("expensesFixedMonthly"); 
    $currentLimitExpFixedMonthly = $gamificationInfoExpFixedMonthly->getCurrentLimit(); 
    $maxLimitExpFixedMonthly = $gamificationInfoExpFixedMonthly->getMaxLimit(); 

但問題是第二個遊戲化類($gamificationInfoExpFixedMonthly)永遠不會被達到/初始化...沒有錯誤將被返回,它只是不會到達那裏..該行下的所有HTML代碼也不會出現......我做錯了什麼?反正我會嘗試更新我的PHP並給出了結果後

+0

什麼給你,如果你傾倒(的var_dump())$ gamificationDeduct得到什麼? – Babblo

+0

我認爲你的問題只是一個空格''gamificationSearch - > getCurrentLimit($ currentUserName);'嘗試'$ gamificationSearch-> getCurrentLimit($ currentUserName);'一個空格爲' - >' –

+0

@Babblo我會得到沒有什麼,如果我var_dump $ gamificationDeduct ..似乎它甚至不能達到那裏..因爲我把日誌文件每次類實例化..但第二次類甚至沒有實例化 – imin

回答

0

你在你的類中的一些問題......讓看:

首先在你的構造你逝去的是從未使用過的變量:

function __construct($belongsTo, $getWebAction) { 
        //  ^this one here what is is doing here??? 

其次您創建使用沒有定義

public function getCurrentLimit($belongsTo) { 
    return $currentLimit; 
       //^here it should be: $this->currentLimit 
} 

而且你必須爲了你的方法使用來定義它在你的類中的局部變量的方法

//.... some more stuff 
private $initialLimit = 3; 
private $maxLimit = 10; 
private $currentLimit = 0; 

多:

public function getCurrentLimit($belongsTo) { 
           //^this is not used at all 
    return $currentLimit; 
       //^here it should be: $this->currentLimit 
} 

修復一切,它應該工作

+0

其實我上面的代碼是從實際代碼中簡化的.. $ belongsTo實際上正在使用。無論如何,我已經剝奪了班級的代碼,儘量減少......但問題仍然存在。我編輯了上面的代碼,反映了我現在使用的完整代碼 – imin