silkfire silkfire - 2 months ago 21
PHP Question

Static variable issue

I have this static variable that I'm defining but I get an error in my code:

..unexpected '$_SERVER' (T_VARIABLE) in ...

class Constants {
const ACCOUNTTYPE_SUPER_ADMIN = 1;
const ACCOUNTTYPE_COMPANY_ADMIN = 2;
const ACCOUNTTYPE_AREA_ADMIN = 3;
const ACCOUNTTYPE_END_USER = 4;

const SAVETYPE_NEW = 0;
const SAVETYPE_EDIT = 1;

const LICENSE_VALIDITY_YEARS = 1;
const LICENSE_VALIDITY_LEFT_MAX = 12;

public static $template_path = $_SERVER['DOCUMENT_ROOT'] . '/../_html/';
}

Answer

You cannot declare a static variable using a variable that way, but you can use a workaround for this:

class Constants {
    ...

    public static $template_path;
}

Constants::$template_path = $_SERVER['DOCUMENT_ROOT'] . '/../_html/';
Comments