
How to Generate a Stable Hash for PHP Arrays
Learn how to generate deterministic hashes for PHP arrays, normalize nested data, avoid key-order issues, and create reliable structured-data fingerprints.
hash(json_encode($data)) changes when keys move and blurs 1 with 1.0. Fingerprint gives PHP data a stable SHA-256 or HMAC fingerprint, whatever the key order, machine or locale, with rules for what to ignore or normalize. It also builds the exact ordered signatures that payment gateways and webhooks expect.
One call for the default, a fluent builder when you need rules.
Maps are ordered canonically at every level, while lists keep their order unless you call unordered().
1, '1', 1.0 and true differ, and null is not a missing key, unless you normalize them.
ignore('items.*.cached_at'), only(), at('email')->trim()->lower(), precision(2), sortBy('id').
SHA-256 by default, any hash() algorithm, hmac($secret), namespaces, and hex, binary or base64 output.
Fingerprint::signature($payload)->fields([...]) rebuilds a gateway's exact message and verifies it in constant time.
result()->canonical() shows the exact bytes behind a fingerprint, so a difference is never a mystery.
Three methods cover most uses; rules are there when you need them.
1use Pharaonic\Fingerprint\Fingerprint; 2 3// The same data gives the same fingerprint, whatever the key order. 4$fingerprint = Fingerprint::make($product); 5 6// Later: has anything changed? 7Fingerprint::verify($product, $fingerprint); // true 8 9// Leave out fields that change on every save.10Fingerprint::for($product)->ignore('updated_at')->make();Quick answers about installing and using Fingerprint.
Deterministic fingerprints of PHP data, whatever the key order, plus ordered HMAC signatures for payment gateways and webhooks. It's a free, open-source PHP package by Pharaonic.
Run composer require pharaonic/php-fingerprint in your project's root directory.
The latest release requires PHP 8.5+.
json_encode() keeps key order, so the same data with keys in another order gives another hash. It also writes 1.0 as 1 and depends on ini settings for floats. Fingerprint orders maps canonically, keeps types apart, and encodes floats from their exact bits.
A fingerprint answers "is this the same data?": key order never matters and you choose what to ignore. A signature answers "does this payload carry the signature a protocol defines?": fields are joined in exactly the declared order, as payment gateways and webhooks require. The two never share a format.
List the gateway's fields in their documented order with Fingerprint::signature($payload)->fields([...]), choose its algorithm and hmac($secret), then call verify() with the signature it sent. Nothing is tied to one gateway: the documentation has complete examples for Paymob (plain PHP and Laravel), Kashier and your own webhooks.
Yes. The canonical form never depends on the locale, ini settings or the PHP version, and hand-written golden vectors check it on every supported PHP line. Only rules that rely on Unicode tables or timezone databases can differ between builds, and the documentation lists them.
No. Fingerprint is plain PHP with no runtime dependency besides ext-mbstring.
Yes. Fingerprint is open source under the MIT license, so you can use it in personal and commercial projects.
Read the Fingerprint documentation for setup, rules, signatures and usage examples.
Open an issue or a pull request on GitHub, or ask in the Pharaonic Discord.
Practical guides that use PHP Fingerprint, or solve the problem it was built for.

Learn how to generate deterministic hashes for PHP arrays, normalize nested data, avoid key-order issues, and create reliable structured-data fingerprints.
Read the full documentation for canonical rules, paths and wildcards, filters, string, number and date normalization, list ordering, objects, hashing and HMAC, ordered signatures, files and streams, and debugging.