exit and ob_*
| From: | Philip Thompson | Date: | Fri, 12 Oct 2007 19:03:32 +0000 |
| Subject: | exit and ob_* | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-263160@lists.php.net to get a copy of this message | ||
Hi. This is weird. Here's my structure. I have an index.php file that just
includes the content depending on what page the user is on. So, because of
potential redirection from those sub-pages, I call ob_start() before any
output (in index.php). I'm doing some testing and I'm wanting to see what
information's in a variable, etc. So, I display the variable contents and
call 'exit' so that the page doesn't continue and get redirected elsewhere.
However, when I call 'exit' on one of these sub-pages, I get no output from
that sub-page.
During testing, I took out the redirection and commented the exit line. The
output displayed. Before commenting the exit function call, I called
ob_clean to see if it had something to do with there being content in the
buffer - the content of the sub-page showed WITH the exit. Why would no
information show when calling exit(), even if ob_start had been called? I've
never had to deal with this before.
[examples]
// This is content from a sub-page called from index.php
[example code: does not work]
echo 'hi';
exit;
// 'hi' does NOT display
...
[example code: does work]
ob_clean();
echo 'hi';
exit;
// 'hi' DOES display
...
[/examples]
I suppose this isn't a big deal during production, but during testing it's
really frustrating. Does anyone have any suggestions as to why 'exit' is
functioning (no pun intended) this way? Note: I do want what's currently in
the buffer to be sent to the browser, so I don't want to have to call
ob_clean. Any thoughts?
Another person (*francois at bonzon dot com) *mentions this on the PHP exit
page <http://www.php.net/exit>, but I'm still not
sure why it happens.
Thanks in advance,
~Philip