What's the best way to verify that an element is ready for use in a foreach() loop in php?
<p>example:  </p>

<pre><code>foreach($boxes as $box) {
    echo "$box \n";
}
</code></pre>

<p>Used to be fairly easy, I could just wrap the foreach around a check like:  </p>

<pre><code>if(is_array($boxes) &amp;&amp; count($boxes) &gt; 0) {
    //foreach loop here
}
</code></pre>

<p>Without having to worry about a warning getting thrown if for whatever reason bad input was passed to the $boxes array.  </p>

<p>When Iterators, were added to the mix, this no longer works, as Iteratable objects are not arrays.  So, I have a few solutions, but am wondering if there is a 'best practice' for this.</p>

<pre><code>// 1:
if($boxes instanceof Traversable &amp;&amp; count($boxes) &gt; 0) {
    //foreach loop here
}

// 2:
if($boxes &amp;&amp; count($boxes) &gt; 0) {
    //foreach loops here
}
</code></pre>

<p>There are others, but these seem like the most obvious.  Anyone have any suggestions.  PHP docs seem to be silent. </p>
