Problem with accessing class members as an array in PHP class
<p>I'm trying to integrate the FedEx tracking class into my application.  The class takes a SOAP response and puts it into a hierarchical class structure.  I access the values like this: </p>

<pre><code>$city = $response-&gt;TrackDetails-&gt;Events[$i]-&gt;Address-&gt;City;
</code></pre>

<p>This works fine for most cases.  The problem I am having is when there is just one event for a given shipment, I get an error saying that I cannot treat the class as an array.  Since there is just one event, I need to access it without the array index using: </p>

<pre><code>$city = $response-&gt;TrackDetails-&gt;Events-&gt;Address-&gt;City;  
</code></pre>

<p>Is there a way to deal with this without doing something like this: </p>

<pre><code>if($num_events==1){
   $city = $response-&gt;TrackDetails-&gt;Events-&gt;Address-&gt;City; 
}else{
   $city = $response-&gt;TrackDetails-&gt;Events[$i]-&gt;Address-&gt;City;
}
</code></pre>

<p>There are a ton of data fields that fall into this issue, so I don't want to use something so cumbersome if I can avoid it.  Any ideas?  </p>
