Table of Contents

PHP - Output Buffer

About

An output buffer is a mechanism to capture all input of output function

Note that once the buffer is above its max limit set by output-buffering (get its actual size with ob_get_length), there is automatic flush.

Basic

ob_start();
echo "My output"
print "Whatever"
ob_get_contents();
ob_end_clean();

Nested / Level

This is a nested feature meaning that a sub-function may also create and end a capture session (ob_start, ob_end) to capture the output of its own instructions

ie:

Support

phpunit: Test code or tested code did not (only) close its own output buffers

See the dedicated page: How to solve Test code or tested code did not (only) close its own output buffers