title: How can I use var_dump + output buffering without memory errors?
body: <p>I'm using a debugging aid in an application that uses <code>var_dump()</code> with output buffering to capture variables and display them. However, I'm running into an issue with large objects that end up using up too much memory in the buffer.</p>
  
  <pre><code>function getFormattedOutput(mixed $var) {
    if (isTooLarge($var)) { 
      return 'Too large! Abort!'; // What a solution *might* look like
    }
  
    ob_start();
    var_dump($var); // Fatal error:  Allowed memory size of 536870912 bytes exhausted
    $data = ob_get_clean();
  
    // Return the nicely-formated data to use later
    return $data
  }
  </code></pre>
  
  <p>Is there a way I can prevent this? Or a work-around to detect that it's about to output a gigantic amount of info for a particular variable? I don't really have control which variables get passed into this function. It could be any type. </p>