http_response_code

FunctionParams and return types changed in PHP 8.0

Get or Set the HTTP response code.

PHP 5.3
PHP 5.4
Added
PHP 5.5-5.6
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2-8.3
PHP 8.4
PHP 8.5
PHP 8.6

http_response_code Function synopsis

http_response_code(int $response_code = 0): int|bool

Parameters

$response_code

OptionalTypeintDefault value0

The optional $response_code will set the response code.

Return value

Typeint|bool

If $response_code is provided, then the previous status code will be returned. If $response_code is not provided, then the current status code will be returned. Both of these values will default to a 200 status code if used in a web server environment.

false will be returned if $response_code is not provided and it is not invoked in a web server environment (such as from a CLI application). true will be returned if $response_code is provided and it is not invoked in a web server environment (but only when no previous response status has been set).

Changes to the http_response_code Function

PHP 8.0

  • Return type added: int|bool
  • Parameter type added for parameter #1 ($response_code): int
  • Parameter default value added for position #1 ($response_code): 0
- http_response_code($response_code)
+ http_response_code(int $response_code = 0): int|bool

PHP 5.4

  • Function added

http_response_code 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 No