What is the explanation for the following syntax?
$var1->$var2 // Note the second $
It means dynamically query a property in an object.
class A {
public $a;
}
// static property access
$ob = new A;
$ob->a = 123;
print_r($ob);
// dynamic property access
$prop = 'a';
$ob->$prop = 345; // effectively $ob->a = 345;
print_r($ob);
so $var1
is an instance of some object, ->
means access to a member of that object and $var2
contains the name of a property.