What is the difference between:
$this->$a
and $this->b
In my class I have this:
class someClass{
public $a;
function aFunction(){
$this->a = 5;
$this->$b = 7;
}
}
what does having the extra '$' do in the $this->$b
There is a lot of difference:
$this->a
refers to the property $a
of your class
$this->$b
in the other hand refers to the property by the name which is stored in variable $b
as a string:
$b = "a";
$this->$b equals $this->a
$b = "hello"
$this->$b equals $this->hello
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With