title: PHP: Accessing an object property with a variable
body: <p>Let's assume I have an array of object properties I'd like to access:</p>
  
  <pre><code>$properties = array('foo', 'bar');
  </code></pre>
  
  <p>I'd like to loop through the object and access these properties dynamically (specifically, I'm trying to dynamically handle missing JSON elements based on an array of expected elements):</p>
  
  <pre><code>foreach ($data as $item) {
      foreach ($properties as $property) {
          if (empty($item-&gt;{$property})) {
              // Do something
          }
      }
  }
  </code></pre>
  
  <p>Each $item in $data should have the properties 'foo' and 'bar'.  I'm handling the cases where 'foo' or 'bar' doesn't exist.</p>
  
  <p>I'm trying to get the loop (in line 3) to access $item->{'foo'} and $item->{'bar'}, but it's not working.</p>
  
  <p>Any idea why?  I'm fairly certain it's a matter of syntax, but obviously I haven't been able to figure this out!</p>
  
  <p>Thanks!</p>