ob_start(), ob_get_contents()  do not work in preprocess functions? I tried to catch some HTML output in preprocess function with ob_start() and ob_get_contents(), but the output seems to slip through them. Is output_buffering maybe disabled in Drupal?

This is the pseudo code from mytheme_preprocess_page():

ob_start(); ?&gt;
&lt;div id="block"&gt;
    &lt;span&gt;This is block&lt;/span&gt;
&lt;/div&gt;
&lt;?php $vars['my_block'] = ob_get_contents();


When I do this, I get the &lt;div&gt; output directly and not dumped to $vars['my_block'], as one would expect. My guess is that output buffering is, for some reasons, disabled. I am wondering if that is the case and why.
I think nothing is left on buffer in Drupal. After evaluating each template the rendered output is preserved as value and passed to outer level template. In this scheme Drupal might be getting buffered content and clearing it across each template.

That is why you should look for variables in that scope.