Access variable in class

后端 未结 5 947
孤独总比滥情好
孤独总比滥情好 2021-01-26 01:03

i would like to access an variable, which is in an class (not as an instance of an class) For example

class myclas
{
private $list=array(\'1\',\'2\',\'3\');
[...         


        
5条回答
  •  生来不讨喜
    2021-01-26 01:58

    It needs to be declared as static.

    Example:

    class MyClass {
    
        public static $var = 'foo';
    }
    

    Then to access: MyClass::$var;

提交回复
热议问题