title: Looping on Output Buffers
body: <p>I am seeing some behavior from <code>ob_start()</code> and <code>ob_end_*()</code> that seems very counterintuitive.</p>
  
  <p>In the spirit of neatness, my algorithm is:</p>
  
  <ol>
  <li>Open buffer</li>
  <li>Do some things</li>
  <li>Save the buffer to a string</li>
  <li>Close the buffer</li>
  </ol>
  
  <p>I'm getting the following notices at runtime for each loop case beyond the first case.</p>
  
  <blockquote>
    <p>Notice: ob_end_clean(): failed to delete buffer. No buffer to delete
    in C:...\testing\TestOBError.php on line 21</p>
    
    <p>Notice: ob_end_clean(): failed to delete buffer. No buffer to delete
    in C:...\testing\TestOBError.php on line 21</p>
    
    <p>Notice: ob_end_clean(): failed to delete buffer. No buffer to delete
    in C:...\testing\TestOBError.php on line 21</p>
    
    <p>Current story payload: `one'.</p>
    
    <p>Current story payload: `two'.</p>
    
    <p>Current story payload: `three'.</p>
    
    <p>Current story payload: `four'.</p>
  </blockquote>
  
  <p>Example code (TestOBError.php):</p>
  
  <pre><code>&lt;?php
  class Story {
      public $payload;
      public function __construct($payload) {
          $this-&gt;payload = $payload;
      }
  }
  
  $stories = array();
  $stories[] = new Story('one');
  $stories[] = new Story('two');
  $stories[] = new Story('three');
  $stories[] = new Story('four');
  
  $foo = "";
  
  foreach ($stories as $story) {
      ob_start();
      require 'TestOBError_Foo.php';
      $foo .= ob_get_clean();
      ob_end_clean();
  }
  
  print $foo;
  
  ?&gt;
  </code></pre>
  
  <p>Contents of TestOBError_Foo.php:</p>
  
  <pre><code>&lt;p&gt;Current story payload: `&lt;?php print $story-&gt;payload; ?&gt;'.&lt;/p&gt;
  </code></pre>
  
  <p>Am I just misusing the output buffer?  Can anyone tell me the "right way" to do this?</p>
  
  <p>I am running PHP version 5.4.7.</p>