[ACCEPTED]-Public static variable value-public

Accepted answer
Score: 12

You can't use expressions when declaring 13 class properties. I.e. you can't call something() here, you 12 can only use static values. You'll have 11 to set those values differently in code 10 at some point.

Like any other PHP static 9 variable, static properties may only be 8 initialized using a literal or constant; expressions 7 are not allowed. So while you may initialize 6 a static property to an integer or array 5 (for instance), you may not initialize it 4 to another variable, to a function return 3 value, or to an object.

http://www.php.net/manual/en/language.oop5.static.php

For example:

class Foo {
    public static $bar = null;

    public static function init() {
       self::$bar = array(...);
    }
}

Foo::init();

Or do 2 it in __construct if you're going to instantiate the 1 class.

More Related questions