title: What is the benefit of passing a callback to ob_start compared to just processing the result of ob_get_clean()?
body: <p>I am wondering if there is any real benefit to using this...</p>
  
  <pre><code>function getSomeContent() {
      ob_start(function($content) {
          // ... modify content ...
          return $content;
      }
      // ... output stuff ...
      return ob_get_clean();
  }
  </code></pre>
  
  <p>...as opposed to this...</p>
  
  <pre><code>function getSomeContent() {
      ob_start();
      // ... output stuff ...
      $result = ob_get_clean();
      // ... modify content ...
      return $result;
  }
  </code></pre>
  
  <p>...?</p>
  
  <p>Assume the "output stuff" and "modify content" parts are the same in each case.  The key point is that the "modify content" has changed its location, being in a callback in the first case, and being "inline" in the second case.</p>
  
  <p>Is there a performance benefit of one over the other?  For example, does the second form make two copies of the buffer contents when the first uses only one?  Or is it purely a coding style decision?  Why would <em>you</em> choose one form over the other?</p>
  
  <p>I can see there are differences in scope access, because any variables in the enclosing scope will be available in the "modify content" part of the second example, where they would have to be "passed in" with a <code>use</code> clause in the first example.  In fact this is exactly why I would normally choose the second form.</p>