title: Variables within object operators
body: <p>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:</p>
  
  <pre><code>$var1 = 'available_from';
  $keyValuePairs[$key] = $item-&gt;parent()-&gt;{$var1};
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>$var1 = 'parent()-&gt;available_from';
  $keyValuePairs[$key] = $item-&gt;{$var1};
  </code></pre>
  
  <p>and</p>
  
  <pre><code>$var1 = 'parent()';
  $var2 = 'available_from';
  $keyValuePairs[$key] = $item-&gt;{$var1}-&gt;{$var2};
  </code></pre>
  
  <p>So the question is whether there is a way to do this.</p>