title: PHP dynamic object property is there a way to make it work?
body: <p>So I know I can do something like this in PHP:</p>
  
  <pre><code>&lt;?php
  
      $x = 'a';
      $a = 5;
      echo $$x;
  </code></pre>
  
  <p>Which will output 5;</p>
  
  <p>But it doesn't work with objects/properties. Is there a way to make this code work?</p>
  
  <pre><code>&lt;?php
  
  class FooBar
  {
   public $foo;
   public $bar;
  
   public function __construct()
   {
    $this-&gt;foo = 'foo';
    $this-&gt;bar = 'bar';
   }
  }
  
  $FooBar = new FooBar();
  
  $str = 'FooBar-&gt;foo';
  
  echo $$str;
  </code></pre>