I've got a problem to share with you all. The thing is, I would like to extract the value of a complex object having its name stored in a string variable.
As you may know, you can do the following:
$foo = 'Hello World';
$var = 'foo';
echo var_dump($$var); // Output: string(11) "Hello World"
The problem comes when you try to do:
$data = new stdClass();
$data->param["foo"]["bar"] = 'Hello World';
$var = 'data->param["foo"]["bar"]';
echo var_dump($$var); // Output: NULL
I can imagine why the parser can't do this. The only workaround that I can think of is to split $var into smaller chunks ('->', '[', ']', ...) and evaluate it step by step.
Does anyone know a more elegant solution?
Thanks a lot