通过变量调用成员变量?

I have two classes and I am going to create an object from any one of these classes(based on some conditions), say classes are A and B and creating the object '$object' from any of these classes. These classes have some member variables, say A has product_id and B has employee_name. Can I call a member variable in following way (I am getting a parse error now.)

$object = new A; // or B;
$a = "product_id";// or "employee_name";

$object->$a = value;

Wrap it in {} to tell PHP that it should first evaluate the value of $a, and use it's value to find the property in the class.

$object->{$a} = "some value;

Here's a demo

Would this work:

$object->{$a} = value;