views:

18

answers:

1

Can anyone explain why the following script behaves differently on two different platforms?

Script:

<?php

echo "hello!";

$view_content = ob_get_clean();

echo "'".gettype($view_content)."' >".$view_content."<";

Output 1 (on WampServer 2i - php v5.3.0 - Windows 7 x64 ):

'string' >hello!<

Output 2 ( on MAMP 1.9 - php v5.3.2 - OSX 10.6.4 ):

hello!'boolean' ><

It seems like MAMP is not performing the function 'ob_get_clean()' correctly. I also tried v5.2.13 of php on MAMP and saw the same problem.

I realize that these are different "versions" of php but i feel like this should work. Is there an extension/module I'm missing?

+1  A: 

Probably on 1 host, automatic output buffering is on. I'd advise against that, as it hogs resources that are not needed most of the time. You can use & set it if you rely on it, a better way IMHO is to just call ob_start() when the real need arises.

From the manual:

Return Values
Returns the contents of the output buffer and end output buffering. If output buffering isn't active then FALSE is returned.

Wrikken
Thanks wrikken, Is there another way to accomplish the same task that is more efficient and/or elegant? By 'task', i mean substituting all previous output into some sort of template, demonstrated simply above. I am using this system in my view templating pattern (MVC).
phife757
Wrikken