title: CakePHP 3 - Warning shown due to length of content?
body: <p>I've got a strange problem whereby I'm seeing the following PHP Warnings:</p>
  
  <pre><code>Warning (512): Unable to emit headers. Headers sent in file=/vendor/cakephp/cakephp/src/Error/Debugger.php line=921 [CORE/src/Http/ResponseEmitter.php, line 48]
  Code Context
  Cake\Http\ResponseEmitter::emit() - CORE/src/Http/ResponseEmitter.php, line 48
  Cake\Http\Server::emit() - CORE/src/Http/Server.php, line 105
  [main] - ROOT/webroot/index.php, line 37
  Warning (2): Cannot modify header information - headers already sent by (output started at /vendor/cakephp/cakephp/src/Error/Debugger.php:921) [CORE/src/Http/ResponseEmitter.php, line 148]
  Code Context
  header - [internal], line ??
  Cake\Http\ResponseEmitter::emitStatusLine() - CORE/src/Http/ResponseEmitter.php, line 148
  Cake\Http\ResponseEmitter::emit() - CORE/src/Http/ResponseEmitter.php, line 54
  Cake\Http\Server::emit() - CORE/src/Http/Server.php, line 105
  [main] - ROOT/webroot/index.php, line 37
  Warning (2): Cannot modify header information - headers already sent by (output started at /vendor/cakephp/cakephp/src/Error/Debugger.php:921) [CORE/src/Http/ResponseEmitter.php, line 181]
  Code Context
  header - [internal], line ??
  Cake\Http\ResponseEmitter::emitHeaders() - CORE/src/Http/ResponseEmitter.php, line 181
  Cake\Http\ResponseEmitter::emit() - CORE/src/Http/ResponseEmitter.php, line 55
  Cake\Http\Server::emit() - CORE/src/Http/Server.php, line 105
  [main] - ROOT/webroot/index.php, line 37
  </code></pre>
  
  <p>I'm in development mode (<code>'DEBUG', true</code> in <code>app/config.php</code>). If I set that to <code>false</code> the Warnings disappear, as expected.</p>
  
  <p>The error is originating from this Controller method:</p>
  
  <pre><code>public function ajaxSubstances()
  {
      $this-&gt;autoRender = false;
      $SubstanceModel = new SubstanceModel;
      $data = ['data' =&gt; $SubstanceModel-&gt;getSubstances()];
      debug($data);
  }
  </code></pre>
  
  <p>What I don't understand is that if my <code>$data</code> array only contains, say 20 elements, no Warning is shown. As I gradually add more elements it always shows the Warning once there is a certain number of records (approx >=30 elements).</p>
  
  <p>To check it's not the source data (from <code>getSubstances()</code>) I hardcoded a <code>$data</code> array in, but the same thing happens.</p>
  
  <p>This method will be used as an ajax response and be fed into DataTables. Unfortunately if the Warnings are output, DataTables will show an error because it's not a valid response.</p>
  
  <p>I can't switch <code>debug</code> to <code>false</code> because I need to have that on for the rest of my development. And I'd like to know why this may be happening anyway?</p>
  
  <p>I'm not sure why it's trying to "emit headers" because the header type isn't being changed anywhere in the code - it's outputting everything using <code>debug()</code>, and I also tried <code>var_dump()</code> but the output is still the same <code>text/html</code> content type.</p>