title: Using print_r in an exception?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5762515/putting-print-r-results-in-variable">putting print_r results in variable</a>  </p>
  </blockquote>
  
  
  
  <p>I'm throwing an exception and trying to include a variable in the exception, like so:</p>
  
  <pre><code>throw new Exception('Oh no, an exception! ' . $variable);
  </code></pre>
  
  <p>(Where <code>$variable</code> is an array)</p>
  
  <p>The problem is, this only puts the following in my log file:</p>
  
  <blockquote>
    <p>On no, an exception! Array</p>
  </blockquote>
  
  <p>Unfortunately I'm not an expert at PHP, I'm guessing this could mean one of two things:</p>
  
  <p>1) $variable is an empty array</p>
  
  <p>2) $varialbe is an array with data in it, but outputting it as such in an exception does not output all of its contents</p>
  
  <p>Please let me know if 1) is the case here (I hope it isn't though)</p>
  
  <p>However, if 2) is the case, how can I get more information about <code>$variable</code>? Is it possible to do <code>print_r</code> or <code>var_dump</code> inside the exception like follows:</p>
  
  <pre><code>throw new Exception('Oh no, an exception! ' . print_r($variable));
  </code></pre>
  
  <p>Or will that cause problems?</p>