title: Print_r() to PHP error_log() not working. (non-printing characters)
body: <p>I have a static method in a helper class Utility::error_log() for helping us gracefully debug HUGE objects in PHP.  The method, and it's helper-method Utility::toArray() are below:</p>
  
  <pre><code>static function error_log($message, $data=null, $max=2)
  {
  
      if(is_array($data) || is_object($data))
          $data = print_r(self::toArray($data, $max),true);
      if(is_array($message) || is_object($message))
          $message = print_r(self::toArray($message, $max),true);
  
      if(!empty($data))
          $data = "\n".$data;
  
      if (!strstr($message, PHP_EOL))
          $message = str_pad(" ".$message." ", 50,'=',STR_PAD_BOTH);
  
      error_log($message.$data);
  
  }
  
  static function toArray($object, $max = 2, $current = 0)
  {
      if($current &gt; $max)
          return ucfirst(gettype($object)).'( ... )';
  
      $current++;
      $return = array();
      foreach((array) $object as $key =&gt; $data)
          if (is_object($data))
              $return[$key] = self::toArray($data, $max, $current);
          elseif (is_array($data))
              $return[$key] = self::toArray($data, $max, $current);
          else
              $return[$key] = $data;
  
      return $return;
  }
  </code></pre>
  
  <p>Now that may be a bit to look at, but the gist is, toArray makes a HUGE object (lots of recursion) orders of a magnitude smaller, and returns all properties as either arrays or strings.  Much easier to work with... The idea being that <code>print_r($array,true)</code> then makes the array a string, and we log it.</p>
  
  <p>This doesn't work as expected, however.  The result is:</p>
  
  <pre><code>[05-Apr-2013 05:29:00] ==================================== PERSISTING SUITS &amp; SHIRTS ===================================
  Array
  (
      [
  </code></pre>
  
  <p>And then nothing, where when I call <code>print_r($data)</code> and print to the browser, I get:</p>
  
  <pre><code>Array
  (
      [BRS\PageBundle\Entity\Pageroot_folder_name] =&gt; Pages
      [id] =&gt; 43
      [title] =&gt; Suits &amp; Shirts
      [depth_title] =&gt; Suits &amp; Shirts
      [description] =&gt; ( ... AND SO ON ... )
  </code></pre>
  
  <p>Before you say it is an error_log() length limitation, I will mention that I can successfully <code>$data = var_export($data,true)</code> and send the result to error_log() with no problems:</p>
  
  <pre><code>[05-Apr-2013 06:00:08] ==================================== PERSISTING SUITS &amp; SHIRTS ===================================
  array (
      '' . "\0" . 'BRS\\PageBundle\\Entity\\Page' . "\0" . 'root_folder_name' =&gt; 'Pages',
      'id' =&gt; 43,
      'title' =&gt; 'Suits &amp; Shirts',
      'depth_title' =&gt; 'Suits &amp; Shirts',
      'description' =&gt; ( ... AND SO ON ... )
  </code></pre>
  
  <p>What is the problem?  Why does it work with <code>var_export($data,true)</code>, and <code>print_r($data,false)</code>, but not with <code>print_r($data,true)</code>??</p>