I’m attempting to set up a variable-based object operator in PHP, but am only able to accomplish what I am looking for to a limited extent. For example, the following code allows for variable selection:

$var1 = 'available_from';
$keyValuePairs[$key] = $item->parent()->{$var1};

However, if I want to make the parent selector a variable as well, I no longer seem to be able to. Both of the following methods fail:

$var1 = 'parent()->available_from';
$keyValuePairs[$key] = $item->{$var1};

and

$var1 = 'parent()';
$var2 = 'available_from';
$keyValuePairs[$key] = $item->{$var1}->{$var2};

So the question is whether there is a way to do this.

Edit
Report