mhash()

mhash() — Computes hash.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

The PHP manual marks this function as deprecated (since PHP 8.1): do not use it in new code.

What it does

mhash() applies a hash function specified by algo to the data.

Signature

mhash(int $algo, string $data, ?string $key = null): string|false

Parameters

ParameterTypeWhat it takes
$algointThe hash ID. One of the MHASH_hashname constants.
$datastringThe user input, as a string.
$key?stringIf specified, the function will return the resulting HMAC instead. HMAC is keyed hashing for message authentication, or simply a message digest that depends on the specified key. Not all algorithms supported in mhash can be used in HMAC mode.

Return value

Returns the resulting hash (also called digest) or HMAC as a string, or false on error.

Example

The PHP manual ships no example for mhash(); the signature and the parameter table above are the contract.

Changelog

VersionChange
8.1.0This function has been deprecated. Use the hash_*() functions instead.
8.0.0key is now nullable.

All PHP 8.5 built-in functions

Reference card built from the PHP manual page mhash() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.