How do you access a PHP object's properties?
Also, what is the difference between accessing an object's property with
$this->$property1
vs. $this->property1
?
When I try to use $this->$property1
I get the following error:
'PHP: Cannot access empty property'.
PHP's documentation on object properties has one comment which mentions this, but the comment doesn't really explain in depth.
$property1
// specific variable$this->property1
// specific attributeThe general use on classes is without
"$"
otherwise you are calling a variable called$property1
that could take any value.Example: