title: Trouble loading SimpleXML object for use in foreach loop : Warning: Invalid argument supplied for foreach()
body: <p>I'm trying to load a simple XML object from file using      <code>simplexml_load_file();</code>
  I've been scraping around the internet trying to get a handle on an error with with the subsequent foreach loop.  </p>
  
  <p>I'm getting an invalid foreach argument error:  </p>
  
  <pre><code>Warning: Invalid argument supplied for foreach() in C:Hosting\bnb\assets\reviews.php on line 2
  </code></pre>
  
  <p>If I try different PHP logic handling the XML object, I can get different errors, however the foreach argument has never shown positive, even though a var_dump has no trouble loading till end of file.</p>
  
  <p>Some other errors have been :</p>
  
  <pre><code>Parse error: syntax error, unexpected T_FOREACH in SERVER_PATH on line 646
  
  Or : Warning: Invalid argument supplied for foreach() in SERVER_PATH on line 648
  
  Parse error: syntax error, unexpected '}' in C:Hosting\bnb\index.php on line 658
  </code></pre>
  
  <p>PHP is :</p>
  
  <pre><code>&lt;?php $xml = simplexml_load_file('reviews.xml'); ?&gt;
  &lt;?php foreach ($xml-&gt;bnb-&gt;review as $n_review): ?&gt; 
                      &lt;ul&gt;
                          &lt;li&gt;
                          &lt;div class="avatar"&gt;&lt;a href="#"&gt;&lt;img src="img/svg/audio.svg" alt=""&gt;&lt;/a&gt;&lt;/div&gt;
  
                          &lt;div class="comment_right clearfix"&gt;
                              &lt;div class="comment_info"&gt;
                                  &lt;a href="#"&gt; 
                                      &lt;?php echo $n_review-&gt;location;?&gt;&lt;/a&gt;&lt;span&gt;|&lt;/span&gt;
                                      &lt;?php echo $n_review-&gt;date;?&gt; 
                              &lt;/div&gt;
                              &lt;p&gt;
                                   &lt;?php echo $n_review-&gt;quote; ?&gt;
                              &lt;/p&gt;
                          &lt;/div&gt;
                          &lt;/li&gt;
                      &lt;/ul&gt;
  &lt;?php endforeach; ?&gt;
  </code></pre>
  
  <p>Some people mention not using HTTP (as this can be blocked by server settings), or that preparing a string for the memory control abstraction can help :</p>
  
  <pre><code>//$feed = file_get_contents('ABSOLUTE_URL');
  //$items = simplexml_load_string($feed);    
  </code></pre>
  
  <p>Somebody else mentioned some people may have a PHP version that doesn't support anonymous functions.  Is it ever necessary to prepare a new array() or new <code>SimpleXMLElement()</code></p>
  
  <p>Requested Edit:
  XML is :  </p>
  
  <pre><code>&lt;bnb&gt;  
      &lt;review&gt;  
          &lt;quote&gt;&lt;/quote&gt;  
          &lt;location&gt;&lt;/location&gt;  
          &lt;date&gt;&lt;/date&gt;  
      &lt;/review&gt;  
      &lt;review&gt;  
          &lt;quote&gt;&lt;/quote&gt;  
          &lt;location&gt;&lt;/location&gt;  
          &lt;date&gt;&lt;/date&gt;  
      &lt;/review&gt;  
  &lt;/bnb&gt;  
  </code></pre>