类变量的访问 [英] Access variable in class
本文介绍了类变量的访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想访问一个变量,它是在一个类(不作为一个类的实例)
例如:
类myclas
{
私人$列表=阵列('1','2','3');
[...]
}
我需要访问以这种方式$列表的值:MyClass的:: $表(巫婆is'n可能)。
是否有其他办法吗?
感谢您。
//编辑:谢谢大家的回答!是否有可能使用一个私有变量的值作为一个公众?
类myclas
{
私人$ _list =阵列('1','2','3');
公共静态$ staticList = $ _名单;
[...]
}
现在,我得到一个错误意外T_VARIABLE
解决方案
类myclas
{
公共静态$列表=阵列('1','2','3');
}
MyClass的:: $名单;
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');
[...]
}
I need to access the values of $list in that way: myclass::$list (witch is'n possible). Is there an alternative way?
Thank you.
//Edit: Thank you all for the answer! Is it possible to use an private variable as values for an public?
class myclas
{
private $_list=array('1','2','3');
public static $staticList=$_list;
[...]
}
Right now, i get an error "unexpected T_VARIABLE"
解决方案
class myclas
{
public static $list=array('1','2','3');
}
myClass::$list;
这篇关于类变量的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文