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
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. And I didn't find anything on Google that could explain what I want.
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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.