ob_start

FunctionParams and return types changed in PHP 8.0

Turn on output buffering.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1-8.2
PHP 8.3
PHP 8.4
PHP 8.5

ob_start Function synopsis

ob_start(
    $callback = null,
    int $chunk_size = 0,
    int $flags = PHP_OUTPUT_HANDLER_STDFLAGS
  ): bool

Parameters

$callback

OptionalDefault valuenull

An optional $callback callable may be specified. It can also be bypassed by passing null.

$chunk_size

OptionalTypeintDefault value0

If the optional parameter $chunk_size is passed, the buffer will be flushed after any block of code resulting in output that causes the buffer's length to equal or exceed $chunk_size. The default value 0 means that all output is buffered until the buffer is turned off. See for more details.

$flags

OptionalTypeintDefault valuePHP_OUTPUT_HANDLER_STDFLAGS

The $flags parameter is a bitmask that controls the operations that can be performed on the output buffer. The default is to allow output buffers to be cleaned, flushed and removed, which can be set explicitly via the

    buffer control flags
   .
   See 
   for more details.

$flags accepts one or a bitmask of the following constant values:

Return value

Typebool

Returns true on success, false on failure

Changes to the ob_start Function

PHP 8.0

  • Return type added: bool
  • Parameter name of parameter #1 changed: $user_function to $callback
  • Parameter default value added for position #1 ($callback): null
  • Parameter type added for parameter #2 ($chunk_size): int
  • Parameter default value added for position #2 ($chunk_size): 0
  • Parameter type added for parameter #3 ($flags): int
  • Parameter default value added for position #3 ($flags): PHP_OUTPUT_HANDLER_STDFLAGS
  ob_start(
-     $user_function,
+     $callback = null,
-     $chunk_size,
+     int $chunk_size = 0,
-     $flags
+     int $flags = PHP_OUTPUT_HANDLER_STDFLAGS
-   )
+   ): bool

ob_start Function Availability

PHP VersionAvailability
PHP 8.5Upcoming Release Yes
PHP 8.4Supported (Latest) Yes
PHP 8.3Supported Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Security-Fixes Only Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes