In PHP, where does the output buffer print to? What things print to it?

Viewed 3930

PHP has many different ways to print things, and I don't understand the difference between them. There are at least the following:

  • stdout and stderr. These can be denoted as php://stdout and php://stderr. There are also constants STDOUT and STDERR, and I think these refer to the same thing. So far, so good; these are standard.
  • php://output. What is this? Where does it go? Is it a synonym for php://stdout, or something else? The docs say it writes "to the output buffer mechanism", but I don't know where the contents of this buffer go after that.
  • print and echo. The docs say that these print to php://output. They are both language constructs, but at a guess, the difference is that print is an expression, but echo is a statement.
  • printf and many friends. Do these all also go to php://output?
  • Escaping. There are lots of alternative syntaxes for escaping, but I'm guessing they all have the same semantics. But what are the semantics? Where does the escaped text get printed to? Also to php://output? Currently, I understand ?>foo<?php as syntactic sugar for echo 'foo';; is this correct?

Are there more ways of doing output? What exactly are the differences? What settings and environments affect their behavior?

1 Answers
Related