I have some php code that works similar to this:
$var1 = 'Variable 1';
$var2 = 'Variable 2';
class myClass {
function __construct() {
$this->var1 = $GLOBALS['var1'];
$this->var2 = $GLOBALS['var2'];
}
public function returnVars() {
return $this->var1 . ' ' . $this->var2; //Works fine
}
public static function returnVars2() {
//What should I do here?
}
}
If I instantiate this class using $myClass = new myClass(), I can use the returnVars() method or just get var1 and var2 from the class just fine. My problem is I need to use the global variables $var1 and $var2 within the static method returnVars2(). I can't use this $this keyword because the class isn't instantiated (and they get declared inside the constructor), but I still can't access the global variables normally.
Any suggestions are greatly appreciated!
globalkeyword?$GLOBALSor by using theglobaldeclaration. What's the problem?