1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Global variable and item class

Discussion in 'Development' started by gistrec, Feb 28, 2017.

  1. gistrec

    gistrec Witch

    Messages:
    68
    GitHub:
    gistrec
    When I write:
    public static $test = Item::get(262, 0, 1);
    I have fatal error:
    Constant expression contains invalid operations in <public static $test = Item::get(262, 0, 1);>
    Why? :c
     
  2. LilCrispy2o9

    LilCrispy2o9 Spider Jockey

    Messages:
    43
    GitHub:
    lilcrispy2o9
    I might be wrong but it may be because you cant call a function within static variables
     
    Muqsit, corytortoise and gistrec like this.
  3. gistrec

    gistrec Witch

    Messages:
    68
    GitHub:
    gistrec
    I try static and no static :)
    But now, I create array in onEnable() -> no longer error :)
     
    Last edited: Mar 1, 2017
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PHP:
    public static $test null;

    public function 
    onEnable(){
        
    self::$test Item::get(26201);
    }
     
    jasonwynn10 and gistrec like this.
  5. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    you'd better use __construct here, because that can be used in all classes that will be instantiated (and even PluginBase extending classes)
    @gistrec you can also add an static init function
     
    gistrec and Muqsit like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.