[英]How can I access my classe's var inside the class?
I have a class: 我有一堂课:
class MyClass {
public $a = 'blablabla';
}
And I want to access the variable $a
inside the class without needing to use any function, like 我想在类中访问变量$a
而不需要使用任何函数,例如
class MyClass {
public $a = 'blablabla';
public $b = $a;
}
I tried using public $b = $this->a
, public $b = MyClass->a
, and many other alternative ways to try to do what I want, and nothing. 我尝试使用public $b = $this->a
, public $b = MyClass->a
以及许多其他替代方法来尝试执行我想要的操作,而没有进行任何操作。 And I didn't find anything on Google that could explain what I want. 而且我在Google上找不到任何可以解释我想要的东西。
Could someone please help me? 有人可以帮我吗? Thanks. 谢谢。
I am not sure why a simple variable call will not work, but you can try: 我不确定为什么简单的变量调用不会起作用,但是您可以尝试:
class MyClass {
public $a = 'blablabla';
function geta(){
return $this->a;
}
$b=geta();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.