title: session_start() works after output being sent
body: <p>I just noticed something strange. I thought that, as PHP's manual says, <code>session_start()</code> must be called before any output is sent to the browser:</p>
  
  <blockquote>
    <p>To use cookie-based sessions, <strong>session_start()</strong> must be called before outputing anything to the browser.</p>
  </blockquote>
  
  <p>So, just for curiosity, I've created two scripts. One is <strong>write.php</strong>:</p>
  
  <pre><code>&lt;?php
  echo 'foo';
  
  session_start();
  $_SESSION['bar'] = 'baz';
  ?&gt;
  </code></pre>
  
  <p>And the other one is <strong>read.php</strong>:</p>
  
  <pre><code>&lt;?php
  echo 'foo';
  
  session_start();
  var_dump($_SESSION['bar']);
  ?&gt;
  </code></pre>
  
  <p>And surprisingly, the session is written and read even after <code>echo</code>ing <strong>foo</strong>.</p>
  
  <p>However, if I add a call to <code>flush()</code> after the <code>echo</code>s, Apache's error log reports:</p>
  
  <blockquote>
    <p>[Tue Jan 03 11:57:21 2012] [error] [client 127.0.0.1] PHP Warning:  session_start(): Cannot send session cache limiter - headers already sent in /var/www/sessions/write.php on line 5
    [Tue Jan 03 11:57:21 2012] [error] [client 127.0.0.1] PHP Stack trace:
    [Tue Jan 03 11:57:21 2012] [error] [client 127.0.0.1] PHP   1. {main}() /var/www/sessions/write.php:0
    [Tue Jan 03 11:57:21 2012] [error] [client 127.0.0.1] PHP   2. session_start() /var/www/sessions/write.php:5</p>
  </blockquote>
  
  <p>So, my questions is: why is the session written correctly after <code>echo</code>ing something? Isn't it immediately sent to the browser? And, if so, does it mean I can start the session anywhere, as long as I don't call <code>flush()</code> before?</p>