2013-02-09 3 views
0

클래스에서 역할을하는 간단한 변수를 사용하고 싶습니다. 그러나 이것은 작동하지 않습니다.PHP 클래스의 GLOBAL 변수

$GLOBALS['world'] = "Isara"; 

class Character{ 
    var $name; 
    var $status; 
    static $content; 
    function __construct($name){ 
     $this->name=$name; 
     $this->getCharInfo(); 
    } 

    private function getCharInfo(){ 
     if(empty(self::$content)){ 
      self::$content = file_get_contents("http://www.tibia.com/community/?subtopic=worlds&world=$GLOBALS['world']",0); 

답변

3

$GLOBALS[...]을 사용하여 전역 변수에 액세스하는 것이 정확합니다. 그러나 배열 접근자를 문자열에 포함 할 때는 변수를 대괄호로 묶어야합니다.

file_get_contents("... {$GLOBALS['world']}"); 
file_get_contents("... " . $GLOBALS['world']); 

나 :

global $world; 
file_get_contents("... $world"); 

그래서, 대신

file_get_contents("... $GLOBALS['world']"); 

의 다음 중 하나를 사용할 수 있습니다