Simple question:
If I enable output buffering...
ob_start();
$a = true;
header('Location: page.php');
$a = false;
ob_end_flush();
... will $a be registered as false, or will it just redirect the page without processing the command (as it would if output buffering were not enabled)?
Thanks!
Unless you call exit() or die() after the header redirect, $a will be false as the rest of the page continues to parse (with or without the buffering).
Unless you have a special reason, header("Location: ..."); should always be followed by one of the above functions as to not waste cpu cycles or memory.
Output buffering does exactly what the name infers, nothing more. It only buffers the output, not variable assignment or object state. In this case $a would be set to false at the end of the code sample you provided. What happens after that is up to your code execution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With