print_r

FunctionReturn type changed in PHP 8.4

Prints human-readable information about a variable.

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

print_r Function synopsis

print_r(mixed $value, bool $return = false): string|true

Parameters

$value

Typemixed

The expression to be printed.

$return

OptionalTypeboolDefault valuefalse

If you would like to capture the output of print_r, use the $return parameter. When this parameter is set to true, print_r will return the information rather than print it.

Return value

Typestring|true

If given a string, int or float, the value itself will be printed. If given an array, values will be presented in a format that shows keys and elements. Similar notation is used for objects.

When the $return parameter is true, this function will return a string. Otherwise, the return value is true.

Changes to the print_r Function

PHP 8.4

  • Return type changed: string|bool to string|true
- print_r(mixed $value, bool $return = false): string|bool
+ print_r(mixed $value, bool $return = false): string|true

PHP 8.0

  • Return type added: string|bool
  • Parameter name of parameter #1 changed: $var to $value
  • Parameter type added for parameter #1 ($value): mixed
  • Parameter type added for parameter #2 ($return): bool
  • Parameter default value added for position #2 ($return): false
- print_r($var, $return)
+ print_r(mixed $value, bool $return = false): string|bool

print_r Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported 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