Accessing an object property without knowing the name?
<p>I'm writing a PHP script that accesses two different data objects - one is backed by a DB, the other contains session data. They both contain the same fields - i.e. the data that is in the session object will make its way into the DB once it is validated.</p>

<p>I'm trying to write a function that will first check the db-backed object for a value, then check the session-data-backed object for a value. It's not working like I quite expect, however. Here is what I have.</p>

<pre><code>&lt;?php
    function check_cache($field){
            // $App is the DB backed object, $data is the session object
        return $app-&gt;$field ? $app-&gt;$field : $data-&gt;$field ? $data-&gt;$field : '';
    }
?&gt;
</code></pre>

<p>I'd like to be able to call the function like this:</p>

<pre><code>&lt;input type="text" value="&lt;?php echo check_cache('address'); ?&gt;" /&gt;
</code></pre>

<p>...but the function always returns nothing. When I replace the function call with the actual inline code, substituting <code>$field</code> with the field name I want, it works. What am I missing?</p>
