1
//...

<?php
class Essentials {

  //...
  //...

  static $root = $_SERVER['DOCUMENT_ROOT'];
}


//...
?>

Php writing an error

Parse error: syntax error, unexpected '$_SERVER' (T_VARIABLE) in /Users/Dima/Desktop/localhost/YouLose/lib/lib.php on line 17

What's the matter? Outside the class it works. In php $_SERVER is "superglobal" as I know

Subirdcom
  • 91
  • 6

1 Answers1

1

Better initialize it inside the constructor:

<?php
class Essentials {


    static $root;


    public function __construct() {
        self::$root =  $_SERVER['DOCUMENT_ROOT'];
    }
}

?>
pavlovich
  • 1,935
  • 15
  • 20