openssl_random_pseudo_bytes

FunctionParams and return types changed in PHP 8.0

Generate a pseudo-random string of bytes.

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

openssl_random_pseudo_bytes Function synopsis

openssl_random_pseudo_bytes(int $length, &$strong_result = null): string

Parameters

$length

Typeint

The length of the desired string of bytes. Must be a positive integer less than or equal to 2147483647. PHP will try to cast this parameter to a non-null integer to use it.

$strong_result

Passed by reference, OptionalDefault valuenull

If passed into the function, this will hold a bool value that determines if the algorithm used was "cryptographically strong", e.g., safe for usage with GPG, passwords, etc. true if it did, otherwise false

Note that the parameter $strong_result is passed by reference, and contains additional/updated context data that may be useful.

Return value

Typestring

Returns the generated string of bytes.

Changes to the openssl_random_pseudo_bytes Function

PHP 8.0

  • Return type added: string
  • Parameter type added for parameter #1 ($length): int
  • Parameter name of parameter #2 changed: $result_is_strong to $strong_result
  • Parameter default value added for position #2 ($strong_result): null
- openssl_random_pseudo_bytes($length, &$result_is_strong)
+ openssl_random_pseudo_bytes(int $length, &$strong_result = null): string

openssl_random_pseudo_bytes 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