Working with PHP objects
<p>I was previously mostly scripting in PHP and now considering getting "more serious" about it :)</p>

<p>I am working on a hiking website, and I needed to put some values into an object that I then try to pass back to the calling code.</p>

<p>I tried doing this:</p>

<pre><code>$trailhead = new Object ();
</code></pre>

<p>But the system sort of barfed at me.</p>

<p>Then I didn't declare the object at all, and started using it like this:</p>

<pre><code>$trailhead-&gt;trailhead_name = $row['trailhead_name'];
$trailhead-&gt;park_id = $row['park_id'];
</code></pre>

<p>That seemed to work reasonably ok.  But there are at least 3 problems with this:</p>

<ol>
<li><p>Since that code gets executed when getting things from the database, what do I do in case there is more than one row?</p></li>
<li><p>When I passed the $trailhead back to the calling code, the variables were empty</p></li>
<li><p>I actually am maybe better off making a real object for Trailhead like this:</p>

<pre><code>class Trailhead
{
    private $trailhead_name;
    private $park_id;
    private $trailhead_id;

    public function __construct()
    {
        $this-&gt;trailhead_name    =    NULL; 
        $this-&gt;park_id    =    NULL; 
        $this-&gt;trailhead_id    =    NULL;     
    }
}
</code></pre></li>
</ol>

<p>What do people generally do in these situations and where am I going wrong in my approach?  I know its more than one place :)</p>
