hash
Function • Params changed in PHP 8.1
Generate a hash value (message digest).
hash
Function synopsis
hash(
string $algo,
string $data,
bool $binary = false,
array $options = []
): string
Parameters
$algo
Typestring
Name of selected hashing algorithm (e.g. "sha256"
).
For a list of supported algorithms see hash_algos
.
$data
Typestring
Message to be hashed.
$binary
OptionalTypebool
Default valuefalse
When set to true
, outputs raw binary data.
false
outputs lowercase hexits.
$options
OptionalTypearray
Default value[]
An array of options for the various hashing algorithms.
Currently, only the "seed"
parameter is
supported by the MurmurHash variants.
Return value
Typestring
Returns a string containing the calculated message digest as lowercase hexits
unless $binary
is set to true in which case the raw
binary representation of the message digest is returned.
Changes to the hash
Function
PHP 8.1
- Optional parameter added - #4:
array $options = []
hash(
string $algo,
string $data,
- bool $binary = false
+ bool $binary = false,
+ array $options = []
): string
PHP 8.0
- Return type added:
string
- Parameter type added for parameter #1 (
$algo
):string
- Parameter type added for parameter #2 (
$data
):string
- Parameter name of parameter #3 changed:
$raw_output
to$binary
- Parameter type added for parameter #3 (
$binary
):bool
- Parameter default value added for position #3 (
$binary
):false
hash(
- $algo,
+ string $algo,
- $data,
+ string $data,
- $raw_output
+ bool $binary = false
- )
+ ): string
hash
Function Availability
hash
Function AvailabilityPHP Version | Availability |
---|---|
PHP 8.5Future Release | Yes |
PHP 8.4Upcoming Release | Yes |
PHP 8.3Supported (Latest) | Yes |
PHP 8.2Supported | 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 |