Can Anyone Explain This Behavior?
$object = new stdClass();
//This works.
$object->test = "Test";
//This works.
$arbitrary = "arbitrary";
$object->$$arbitrary = "again, testing";
//This works.
$object->id = "2";
//This fails
$test = "id";
$object->$$test = "2"; // On this line.
I’m trying to set the ‘id’ property through a dynamic variable name. I can set the ‘id’ property fine if I explicitly state it. I can set other variable names dynamically – i.e ‘arbitrary’. Any suggestions?
There is no variable named
$id.Try this