hash_init
Initialize an incremental hashing context.
hash_init Function synopsis
hash_init(
string $algo,
int $flags = 0,
string $key = "",
array $options = []
): HashContext
Parameters
$algo
Typestring
Name of selected hashing algorithm (e.g. "sha256").
For a list of supported algorithms see hash_algos.
$flags
OptionalTypeintDefault value0
Optional settings for hash generation, currently supports only one option:
HASH_HMAC. When specified, the $key
must be specified.
$key
OptionalTypestringDefault value""
When HASH_HMAC is specified for $flags,
a shared secret key to be used with the HMAC hashing method must be supplied in this
parameter.
$options
OptionalTypearrayDefault value[]
An array of options for the various hashing algorithms.
Currently, only the "seed" parameter is
supported by the MurmurHash variants.
Return value
TypeHashContext
Returns a Hashing Context for use with hash_update,
hash_update_stream, hash_update_file,
and hash_final.
Changes to the hash_init Function
PHP 8.2
- Attribute added for parameter
$key:#[SensitiveParameter]
PHP 8.1
- Optional parameter added - #4:
array $options = []
hash_init(
string $algo,
int $flags = 0,
- string $key = ""
+ string $key = "",
+ array $options = []
): HashContext PHP 8.0
- Return type added:
HashContext - Parameter type added for parameter #1 (
$algo):string - Parameter name of parameter #2 changed:
$optionsto$flags - Parameter type added for parameter #2 (
$flags):int - Parameter default value added for position #2 (
$flags):0 - Parameter type added for parameter #3 (
$key):string - Parameter default value added for position #3 (
$key):""
hash_init(
- $algo,
+ string $algo,
- $options,
+ int $flags = 0,
- $key
+ string $key = ""
- )
+ ): HashContext hash_init Function Availability
hash_init Function Availability| PHP Version | Availability |
|---|---|
| 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 |