2012-02-24 32 views
0

我已經閱讀了與這個問題有關的所有主題,但他們都沒有爲我工作。製作一個變量用於類功能

我包括一個類文件,幷包括我定義應該在類文件中使用的遊戲ID之前

here is my code : 

$game_id = (int) $_GET['g']; // get id 
define("_GAMEID",$game_id); 

function show_game(){ 
     global $game_id; 
     include("includes/class.files.php"); 
       new game_class(); 

} 

// class.files.php 
class game_class{ 

    public function getContent() { 
     global $game_id; 
     die($game_id); 
     // die(_GAMEID); 
    //die($GLOBALS['game_name']); 
    //die($this->game_id); 

     } 


} 

真好笑沒有這些作品中,我得到了遊戲的電流id;

+0

$ _GET已經是全球性的。 – 2012-02-24 06:55:43

+0

等等是什麼?爲什麼在運行課程時它會返回0。 – 2012-02-24 06:58:52

+0

不要這麼難過:)你真的得到了,我的意思是在你的vodooo之前? – 2012-02-24 07:04:47

回答

0

當你第一次定義:

global $game_id; //include this too!! 
$game_id = (int) $_GET['g']; // get id 
+0

即使我全球它的功能,但你的方式也無法正常工作。它返回0。 – 2012-02-24 06:58:21

+1

@MacTaylor $ _GET ['g']'在這種情況下必須爲零或NaN,你可以檢查你的'print_r($ _ GET);'並顯示零似乎正在工作,因爲整數轉換是發生在這裏。 – linuxeasy 2012-02-24 07:01:48

+0

爲什麼不把它存入session? – Bert 2012-02-24 07:07:21