I am trying to use a variable in an array within my class
class MyClass {
public static $a = "World";
public static $b = array("Hello" => self::$a);
}
This code doesn't work. Should I be using MyClass::$a
or something else. Any ideas?
You probably can instatiate them at runtime:
Or you can create a static initialization method:
|
|||||||||
|
If your $a won't change, make it a constant
|
|||||||||
|
|
|||||||||||||||||
|
self::$a
requires a runtime evaluation. If your $a isn't going to change, make it a constant – Mark Baker Dec 29 '13 at 12:14$b
in the class constructor. – Barmar Dec 29 '13 at 12:16static
– Mark Baker Dec 29 '13 at 12:17if (!$b) { self::$b = array(...) }
. – Barmar Dec 29 '13 at 12:20